Skip to content

Instantly share code, notes, and snippets.

@jessitron
Last active August 29, 2015 14:00
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 jessitron/11200014 to your computer and use it in GitHub Desktop.
Save jessitron/11200014 to your computer and use it in GitHub Desktop.
JavaScript illustrates that methods are the same as functions with an implicit parameter "this"
var completeSale = function(num) {
console.log("Sale " + num + ": selling " + this.items + " to " + this.customer);
}
var foo = {
customer: "Fred",
items: ["carrot","eggs"],
complete: completeSale
};
console.log("method style:")
foo.complete(99);
console.log("function style:")
completeSale.call(foo, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment