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

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c++ - CryptStringToBinary API behavior -