Created
February 13, 2014 09:14
-
-
Save abrjagad/8972113 to your computer and use it in GitHub Desktop.
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
//Invocation as a function | |
//this refers to window | |
function creep() { | |
return this; | |
} | |
console.log(creep() === window, "Creeping in the window"); | |
var sneak = creep; | |
console.log(sneak() === window, "Sneaking in the window"); | |
//Invocation as a method | |
//Function is declared as a mEthod of a Object | |
//this refers to object that called the Method | |
var ninja1 = { | |
skulk: function () { | |
return this; | |
} | |
}; | |
console.log(ninja1.skulk() === ninja1, "The 1st ninja is skulking"); | |
var ninja2 = { | |
skulk: creep | |
}; | |
console.log(ninja2.skulk() === ninja2, "The 2nd ninja is skulking"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment