Use the anonymous function (immediate execution of the function) in js to implement dynamic parameters or dynamically change the object Attributes. I used it once in a while, hoping to give a tip to friends who are looking for it.
All codes:
(function(){ console.info('这是一个匿名函数,会立即执行。'); })(); function count(a, b){ console.info(a+b); } //传入一个匿名函数 count((function(){return 100;})(), 10); //设置一个匿名函数的属性 var ob = { count : (function(){return 100;})(), name : 'xx' }; console.info(ob);
The above is the detailed content of Analyze dynamic parameter transfer and dynamic attributes of JavaScript.. For more information, please follow other related articles on the PHP Chinese website!