Created
August 16, 2011 13:12
-
-
Save evilpie/1149041 to your computer and use it in GitHub Desktop.
blabla
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
so well | |
var f = function () {}; | |
var bound = f.bind({}); | |
(new bound) instanceof bound; | |
V = new bound; | |
bound[[HasInstance]](V); | |
/* inside 15.3.4.5.3 [[HasInstance]] (V) */ | |
if (!bound[[Target])) | |
throw; | |
target = bound[[Target]] | |
target[[HasInstance]](V) | |
/* target is just |f| */ | |
/* at this point this is the same as (new bound) instanceof f */ | |
/* 15.3.5.3 [[HasInstance]] (V) */ | |
if (!IsObject(V)) | |
throw; | |
prototype = target.prototype; | |
do { | |
V = V.__proto__; /* V proto is going to be f.prototype, because (new bound) is about the same as (new f) | |
if (V === null) | |
return false; | |
if (V === prototype) | |
return true; /* yaay ! */ | |
} while (true); | |
[[HasInstance]] of the target
will not find bound
in its [[Prototype]] look ups so it should return false
.
I think you misread the spec here it is going to check for [[Prototype]] of (new bound) being equal to target.prototype.
and that means bound
is right out, it should return false
.
Sleep over it and come back here tomorrow. I am going to enjoy the sun :)
Well crap, you guys are right. Here is the V8 bug report and explanation by Luke that made it click for me :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When new bound is called, bound.[[Construct]] is called bound.[[Construct]] is f.[[Construct]] per ES5.1 15.3.4.5 step 13), so |new bound| is like doing |new f|, setting the correct [[prototype]] to the object to be built (f.prototype).
This value is used for testing when bound.[[HasInstance]](which has the return value of f.[[HasInstance]]) is called.
bound.[[Construct]] being f.[[Construct]] and bound.[[HasInstance]] being f.[[HasInstance]] make the two objects enough "connected" so that "new bound instanceof bound" is equivalent to "new f instanceof f" (which is true). If you still disagree, let's post on es5-discuss, hopefully the people who wrote the spec will be able to tell us 1) their intention 2) if the spec matches it.