Skip to content

Instantly share code, notes, and snippets.

@jnvm
Last active August 3, 2016 01:20
Show Gist options
  • Save jnvm/1aa815fd006283166a1f9a40d68a839c to your computer and use it in GitHub Desktop.
Save jnvm/1aa815fd006283166a1f9a40d68a839c to your computer and use it in GitHub Desktop.
in which jnvm makes a fool of himself claiming: bind modifies function, doesn't return new one
var echo=function(){
var echoes=echo.count||10
while(echoes--) this.makeNoise()
}
var dog={
sound:"woof",
makeNoise:function(){ console.log(this.sound) },
}
echo.count=3
var barkAtGrandCanyon=echo.bind(dog)
barkAtGrandCanyon()//echoes 3x, since it's the same function. If it were a new function, it wouldn't have the count property.
//(^FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE^)
echo.count=20
barkAtGrandCanyon()//echoes 20x
@jnvm
Copy link
Author

jnvm commented Aug 3, 2016

..agreed! I didn't actually construct a test of my claim! Bah. Thank you & very sorry.

It's even the first sentence in mdn:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

The bind() method creates a new function

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