Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save subtubes-io/11320741 to your computer and use it in GitHub Desktop.
Save subtubes-io/11320741 to your computer and use it in GitHub Desktop.
Based on example in JavaScript Ninja - John Resig Nifty little caveat regarding recursive function as a property. Key is to use a inline function
var ninja = {
chirp: function signal(n) {
if (n > 1) {
return signal(n-1) + " - chirp";
}
else{
return "chirp";
}
}
};
var samurai = {
whistle : ninja.chirp
};
console.log(samurai.whistle(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment