Quantcast
Channel: User kangax - Stack Overflow
Browsing latest articles
Browse All 41 View Live

Comment by kangax on Changing the execution scope of eval method - strict...

What's the reason for keeping data in an object — and then using with to allow access to it via variables — instead of just using variables in the first place?

View Article



Comment by kangax on Why somebody call "EMCA-262 Edition 6" as "ECMAScript 2015"

Actually, yes, it is an official name now (no matter how silly it sounds) —wiki.ecmascript.org/doku.php?id=harmony:specification_drafts See the front page of latest spec

View Article

Comment by kangax on What is `base value` of `reference` in...

perfectionkills.com/know-thy-reference

View Article

Comment by kangax on Input size vs width

@Kos It kind of was a consensus. Not anymore (with IE and other old browsers) passing away.

View Article

Comment by kangax on Browser support for array.includes and alternatives

kangax.github.io/compat-table/es6

View Article


Comment by kangax on What is the difference between the way that Canvas...

Not yet :( Too many things to do, too little time. We focus on bugs now, architectural imrovements, tests, and text-related functionality — we're the only library with such extensive (interactive) text...

View Article

Comment by kangax on What is the purpose of the var keyword and when should I...

@Snekse let doesn't affect x = 1 part of the answer so the only difference is in var x = 1 vs. let x = 1. This has been documented many times in many places but the 2 main differences are that let is...

View Article

Comment by kangax on Why is using a generator function slower than filling...

ES6 is still largely significantly slower than its ES5 analogues —kpdecker.github.io/six-speed— but will likely improve in the future.

View Article


Comment by kangax on Promise to string - [object Object] or [object Promise]?

According to ecma-international.org/ecma-262/6.0/…'the initial value of the @@toStringTag property is the String value "Promise"'. So Object.prototype.toString.call(...) should indeed return "[object...

View Article


Comment by kangax on Performing a copy and paste with Selenium 2

Corresponding ChromeDriver issue —code.google.com/p/chromedriver/issues/detail?id=30

View Article

Comment by kangax on Accumulating and resetting values in a stream

Ahha, so the trick is to "end" stream with first(), then "resume" with repeat()? Interesting. But also a little confusing. I'd expect repeat() to repeat last value (which is the first combination that...

View Article

Comment by kangax on Accumulating and resetting values in a stream

Great breakdown of a problem and interesting solution, thanks! So using distinctUntilChanged and differentiating between streams via flags is one option. But damn... this is really difficult to...

View Article

Comment by kangax on Are there any advanced apps that are built using fabric js?

Yep, just standard filters. Depends on the size of the image and all the other things happening on the main thread (which could be taking away from the computation power).

View Article


Answer by kangax for What happens if the meta tags are present in the...

This is of course invalid as per HTML4.01. META tags are only allowed within HEAD (just like, say, TITLE) so by putting it into a BODY, you're essentially creating an invalid markup.From the cursory...

View Article

Answer by kangax for Using Chrome Dev Tools With Different ECMAScript standard

No. Currently it's not possible to switch to ES3-only in Chrome.You can activate some of the ES6 features, on top of existing ES5 ones, using "Enable Experimental JavaScript" flag. So you can go...

View Article


Answer by kangax for ES6 Template String testbed

It's only supported in Traceur at the moment.You can play with it in their REPL.es6fiddle.net doesn't seem to support it yet, but probably will soon.Mozilla is working on it so expect to see it in...

View Article

Answer by kangax for How to not remove some knockout-specific comments using...

So... this is now implemented via ignoreCustomComments option.Here's a snippet from our test suite:var input = '<!-- ko if: someExpressionGoesHere --><li>test</li><!-- /ko...

View Article


Image may be NSFW.
Clik here to view.

Text decoration of SVG tspan

I'm seeing inconsistent rendering of SVG <tspan> elements in regards to text-decoration.Using this simple testcase:<text font-family="Helvetica" x="0" y="50" font-size="30"...

View Article

Answer by kangax for JavaScript ES6: Test for arrow function, built-in...

Believe it or not...Testing for presence of "=>" in string representation of a function is likely the most reliable way (but not 100%).Obviously we can't test against either of 2 conditions you...

View Article

Answer by kangax for Does any version of PhantomJS support javascript...

Since PhantomJS 2.0 is based on 7 month old WebKit and considering that even latest WebKit doesn't support generators yet, I'm pretty sure PhantomJS 2.0 does not support them.We'll be adding it to the...

View Article

Answer by kangax for What is Prologue Directives?

No need for documentation. Just look in the source.A Directive Prologue is the longest sequence of ExpressionStatement productions occurring as the initial SourceElement productions of a Program or...

View Article


Answer by kangax for 'innerText' works in IE, but not in Firefox

Update: I wrote a blog post detailing all the differences much better.Firefox uses W3C standard Node::textContent, but its behavior differs "slightly" from that of MSHTML's proprietary innerText...

View Article


Answer by kangax for Subclassing native objects

Yes, it is now possible in ES6:class R extends RegExp {}var r = new R("baz", "g");return r.exec("foobarbaz")[0] === "baz"&& r.lastIndex === 9;We have a test for it in ES6 compat table where you...

View Article

Accumulating and resetting values in a stream

I'm playing with Reactive Programming, using RxJS, and stumbled upon something I'm not sure how to solve.Let's say we implement a vending machine. You insert a coin, select an item, and the machine...

View Article

Answer by kangax for Create spots or strips pattern in Fabric.js

I can find plenty of examples using an image as a pattern but not other shapes or polygons.Using that same dynamic patterns demo, you would just need to replace:...

View Article


Answer by kangax for How to set a background image for a FabricJS object

You can do this by clipping an image with a circle. Take a look at this demo.Pattern offsets is something that's been on a roadmap. I just went ahead and implemented them. Take a look at this demo....

View Article

Image may be NSFW.
Clik here to view.

Answer by kangax for Fabric.js Clip Canvas (or object group) To Polygon

You can just render a shape inside canvas.clipTo :)I just loaded a random SVG shape in kitchensink and did this:var shape = canvas.item(0);canvas.remove(shape);canvas.clipTo = function(ctx) {...

View Article

Answer by kangax for Javascript Method Naming lowercase vs uppercase

A popular convention in Javascript is to only capitalize constructors (also often mistakenly called "classes").function Person(name) { this.name = name;}var person = new Person('John');This convention...

View Article

Answer by kangax for How do I make a "public static field" in an ES6 class?

You make "public static field" using accessor and a "static" keyword:class Agent { static get CIRCLE() { return 1; } static get SQUARE() { return 2; }}Agent.CIRCLE; // 1Looking at a spec, 14.5— Class...

View Article



Answer by kangax for Fabric.js object:selected, object not selected

You need:canvas.on('selection:cleared', function() { ...});Take a look at Events Demo and Events Section in tutorial.

View Article

Answer by kangax for Can I disable ECMAscript strict mode for specific...

No, you can't disable strict mode per function. It's important to understand that strict mode works lexically; meaning — it affects function declaration, not execution. Any function declared within...

View Article

Answer by kangax for What are some of the best reference sites for HTML and...

The Unofficial online ECMAScript-262 3rd ed. specification and Annotated ECMAScript 5.1 are very helpful.

View Article

Answer by kangax for Event detect when css property changed using Jquery

NoteMutation events have been deprecated since this post was written, and may not be supported by all browsers. Instead, use a mutation observer.Yes you can. DOM L2 Events module defines mutation...

View Article


Image may be NSFW.
Clik here to view.

Casting shadow on MeshPhongMaterial or MeshLambertMaterial in Three.js

I feel like I'm missing something simple here.I used JSFiddle by @WestLangley, which demonstrates how to cast a shadow from an object onto a plane.Everything works as expected when the plane is filled...

View Article

Answer by kangax for Find the coordinates of the corners of a rotated object...

Yes, of course.We store those coordinates in object's oCoordsoCoords.tl.x, oCoords.tl.y // top left corner oCoords.tr.x, oCoords.tr.y // top right corneroCoords.bl.x, oCoords.bl.y // bottom left...

View Article

Image may be NSFW.
Clik here to view.

Canvas pattern offset

I'm trying to modify the origin of canvas pattern but can't achieve quite what I want.I need to draw a line filled with a dotted pattern. Dotted pattern is created via createPattern (feeding it...

View Article


Answer by kangax for Return multiple values in JavaScript?

You can do this from ECMAScript 6 onwards using arrays and "destructuring assignments". Note that these are not available in older Javascript versions (meaning — neither with ECMAScript 3rd nor 5th...

View Article


Image may be NSFW.
Clik here to view.

SVG shadow cut off

The SVG I'm working with has a drop shadow via feGaussianBlur filter.The shadow itself is displayed properly, but gets cut off on top and bottom edges.Like so:The SVG in question is:<?xml...

View Article

Image may be NSFW.
Clik here to view.

Answer by kangax for Preventing auto-creation of global variables in Javascript

I made a bookmarklet some time ago to inspect and detect global variables.(source: thinkweb2.com)It has some additional features (like filtering out Prototype.js or Google Analytics properties) too.

View Article

Answer by kangax for MIME Type of Wavefront's OBJ and MTL

According to wikipedia, it's text/plain for .obj.I'm guessing it's text/plain for .mtl files as well, since there's text in them and since it "is a standard defined by Wavefront Technologies for ASCII...

View Article

Three.js multiple materials on object loaded via OBJMTLLoader

I have ".obj" and ".mtl" files of a model and I'm loading it via OBJMTLLoader. ".mtl" specifies texture to apply to a model, and three.js loads model and renders it with applied texture just fine.But...

View Article

Browsing latest articles
Browse All 41 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>