Skip to content

Instantly share code, notes, and snippets.

@abrjagad
Created February 13, 2014 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrjagad/8972113 to your computer and use it in GitHub Desktop.
Save abrjagad/8972113 to your computer and use it in GitHub Desktop.
//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