Skip to content

Instantly share code, notes, and snippets.

@stinoga
Created December 6, 2013 05:07
Show Gist options
  • Save stinoga/7818879 to your computer and use it in GitHub Desktop.
Save stinoga/7818879 to your computer and use it in GitHub Desktop.
Applying arguments to objects. Works especially well if those objects are rabbits.
// 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