Created
November 9, 2014 01:14
-
-
Save snippe/bd4fcde72d5ff509f1d1 to your computer and use it in GitHub Desktop.
Context Manipulation with .apply and .call
This file contains 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
var obj1 = { | |
num : 4 | |
} | |
function multiply(val){ | |
return this.num * val; | |
} | |
console.log(multiply(3)); //impossible because no num defined in window (NaN) | |
console.log(multiply.apply(obj1, [4])); //16 | |
console.log(multiply.call(obj1, 4)); //16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment