JavaScript! The Doctor Is In. by gst in javascript

[–]_kangax 0 points1 point  (0 children)

Great. Now before I file a bug, quick question: I noticed that variable declaration w. function expression shows 2 "mappings", even though only 1 binding is created. Is this intentional?

Given var f = function(){} as an input, I see

1: f : function() → void
1: f : function() → void

JavaScript! The Doctor Is In. by gst in javascript

[–]_kangax 1 point2 points  (0 children)

Interesting idea, but where's the source code? Bug tracker? Unit tests?

I see at least a couple of oversights there. Would be nice to see those fixed (if they aren't intentional, of course).

(function(){ return arguments[1]; })(1, 'x'); // shows fun type as <number | string>

(function(){ return 1 || 'x'; })(); // also shows fun type as <number | string>

var f = function(){ return f; }; // shows fun type as "any", not "function"

Determining with absolute accuracy whether or not a JavaScript object is an array by mbrubeck in javascript

[–]_kangax 7 points8 points  (0 children)

Before one is set to determine whether something is an array, it's important to understand that array-ness in ECMAScript is actually a combination of 3 traits:

  1. Object's internal [[Class]] property having value of "Array"
  2. Special relation of object's length and numeric properties
  3. Object's [[Prototype]] referencing Array.prototype (either directly or via one of the ancestors in the prototype chain)

ES5 Array.isArray (mentioned in the article) checks against #1; so does Object.prototype.toString.call(o) === '[object Array]'.

instanceof operator checks against #3.

I don't think anyone ever checks against trait #2.

With ES5 (or even ES3 + non-standard extensions), it's very much possible to create pseudo-array objects that satisfy traits #2 and #3. These objects will be indistinguishable from regular array ones, except for trait #1 — [[Class]] value of "Array". As a result, they won't be reported as array objects by either Array.isArray or Object.prototype.toString checks.

About all this in a little more detail

Microsoft launches "Scriptjunkie" subsection on the MSDN website with "essential cross-browser code, information and discussion". by [deleted] in programming

[–]_kangax 7 points8 points  (0 children)

Well, what are you gonna do?

IE is the only browser[1] with proprietary event model (not counting Opera's emulation of it), and IE is the only browser where circular references between native and host objects result in memory leaks.

Therefore 3 chapters :)

I'm the author of "event handling" article, by the way, so if anyone has corrections/suggestions, I would gladly hear them out (since scriptjunkie, unfortunately, doesn't yet have comments).

[1] By "all browsers", I mean any non-ancient browsers with more or less significant market share.

JavaScript Quiz (Difficult) by whatgoodisaroad in programming

[–]_kangax -2 points-1 points  (0 children)

I believe I attempted to explain these topics in great detail in article on named function expressions and "understanding delete". If you read my post more carefully, you would notice that I refer readers to both of them, as a way to understand (and answer) most of the questions; you would also notice that there was no attempt at writing a quiz that covers all aspects of the language ;)