Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Created August 16, 2011 13:13
Show Gist options
  • Save DavidBruant/1149046 to your computer and use it in GitHub Desktop.
Save DavidBruant/1149046 to your computer and use it in GitHub Desktop.
bound functions and instanceof
function f(){}
var g = f.bind({});
var newg = new g;
// call g.[[Construct]] (which is f.[[Construct]] per ES5.1 15.3.4.5 step 13)
// so, |new g| is the same as |new f|: an object which has f.prototype as [[Prototype]]
newg instanceof g;
// instanceof g calls the g.[[HasInstance]](newg) (please forgive my skip of reference/GetValue mess)
// As per ES5.1 - 15.3.4.5.3, g.[[HasInstance]](V) is g.[[TargetFunction]].[[HasInstance]](V)
// which is f.[[HasInstance]](V)
// ==> g.[[HasInstance]](newg) === f.[[HasInstance]](newg) === true
@jdalton
Copy link

jdalton commented Aug 16, 2011

discussion continued at: https://gist.github.com/1149041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment