Created
April 26, 2014 14:00
-
-
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
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 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