Skip to content

Instantly share code, notes, and snippets.

@snippe
Created November 9, 2014 01:14
Show Gist options
  • Save snippe/bd4fcde72d5ff509f1d1 to your computer and use it in GitHub Desktop.
Save snippe/bd4fcde72d5ff509f1d1 to your computer and use it in GitHub Desktop.
Context Manipulation with .apply and .call
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