recursion.js (323B)
1 var typed = require('../typed-function'); 2 3 // create a typed function that invokes itself 4 var sqrt = typed({ 5 'number': function (value) { 6 return Math.sqrt(value); 7 }, 8 'string': function (value) { 9 return this(parseInt(value, 10)); 10 } 11 }); 12 13 // use the typed function 14 console.log(sqrt("9")); // output: 3