Created
June 2, 2015 13:11
-
-
Save droxer/3d40dc5a3fd581a0214d to your computer and use it in GitHub Desktop.
javascript bind example.
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
#!/usr/local/bin/node | |
var assert = require("assert") | |
function talk (who) { | |
return this.name + " is talking with " + who | |
} | |
var michael = { | |
name : "michael" | |
} | |
var binded = talk.bind(michael, "Sam") | |
assert.equal(binded(), "michael is talking with Sam") | |
assert.equal(talk.call(michael, "Sam"), "michael is talking with Sam"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment