javascript - Replace normal function with an anonymous function -
how use anonymous function replace normal function accepts this , returns results? please describe how variables being sent , anonymous function.
for instance, replace:
function myfunc(myprop){return [1*myprop,2*myprop,3*myprop];} this.myprop=2; var myarray1=myfunc(this.myprop); with like:
var myarray2=function(){return [1*this.myprop,2*this.myprop,3*this.myprop];}
this maybe want:
var myarray2=(function(myprop){ return [1*myprop,2*myprop,3*myprop];} )(this.myprop); so here define anonymous function(because doesn't have name) , call immediately. this.myprop passed argument.
Comments
Post a Comment