Function#bind [[HasInstance]] question.

# John-David Dalton (14 years ago)

Sorry about the last empty reply, GMail got ahead of itself :D

So Chrome and Firefox disagree on their Function#bind implementation. es5.github.com/#x15.3.4.5.2, es5.github.com/#x15.3.4.5.3

function Bar() {
  return 1;
}
var bound = Bar.bind({});
new bound instanceof bound; // Firefox reports `true`, Chrome `false`
(I think Chrome is right)
new bound instance of Bar; // Firefox and Chrome report `true`

The test262 doesn't appear to cover this case. What is the correct result of new bound instance of bound; and why?

# Luke Hoban (14 years ago)

My interpretation of these spec sections:

(new bound) instanceof bound => (new Bar()) instanceof bound // bind's Construct defers to the targetFunction and ignores bound thisValue => bound.[[HasInstance]](new Bar()) // meaning of instanceof => Bar.[[HasInstance]](new Bar()) // bind's HasInstance defers to the targetFunction => true // normal HasInstance

Similarly for 'new bound instanceof Bar'. IE and Firefox both appear to agree with this result.

Luke

# Allen Wirfs-Brock (14 years ago)

correct, according to the spec, JDD's test should report true. What language in the spec. lead you to think otherwise?

# Dmitry A. Soshnikov (14 years ago)

Once again (if the Twitter's discussion doesn't satisfy you):

Quick overview: gist.github.com/1149186 Detailed overview: dmitrysoshnikov.com/notes/note-1-ecmascript-bound-functions

So the Firefox is correct saying true.

Dmitry.

# John-David Dalton (14 years ago)

Thanks Luke,

Your explanation made it "click". I was going to file a bug report, but found it already existed (from 2010 eeeek). code.google.com/p/v8/issues/detail?id=793