javascript - How to use Arrow function for returning anonymous function -
i have following code in ecma5 , i'm trying replace anonymous function arrow function. how can achieve this? can replace both or 1 or none function arrow function?
var countersetup = function () { var counter = 0; return function () { counter += 1; console.log('increment counter value : ' + counter); return counter; }; }; var counter = countersetup(); counter();
you can try this:
var counter = () => { var counter = 0; return () => { counter += 1; console.log('increment counter value : ' + counter); return counter; } }(); alert(counter()); alert(counter()); alert(counter());
Comments
Post a Comment