// small example by Morten from codesoul.com function oldStyleWayToYell(count) { var res = 'he'; for (var i = 0; i < count; i++){ res += "y"; } return res; } var ninja = { yell: function(n){ return n > 0 ? ninja.yell(n-1) + "a" : "hiy"; } }; $("#oldyell").text(oldStyleWayToYell(5)); $("#newyell").text(ninja.yell(42));
<p> old style way to yell: <span id="oldyell"></span> </p> <p> functional ninja yell: <span id="newyell"></span> </p>
p { margin:20px; font-family: 'Segoe UI',Verdana; } #oldyell {color:red;} #newyell {color:green;}