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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -