Created
December 6, 2013 05:07
-
-
Save stinoga/7818879 to your computer and use it in GitHub Desktop.
Applying arguments to objects. Works especially well if those objects are rabbits.
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
// define the function to see what the rabbits say | |
function speak (line) { | |
console.log("The ", this.adjective, " rabbit says ", line); | |
} | |
// define some rabbit objects | |
var whiteRabbit = {adjective: "white", speak: speak}; | |
var fatRabbit = {adjective: "fat", speak: speak}; | |
// apply an array of arguments to our fatter of the two rabbit objects | |
speak.apply(fatRabbit, ["Yum."]); | |
// OUTPUT | |
The fat rabbit says Yum. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment