Last active
August 29, 2015 14:00
-
-
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"
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 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