开发者

JavaScript anonymous function syntax

开发者 https://www.devze.com 2023-02-13 08:16 出处:网络
The following syntax is present in a .js file. var fun1 = function(fun1_parameter1){ return{ fun2 : function(){

The following syntax is present in a .js file.

var fun1 = function(fun1_parameter1){
  return{
    fun2 : function(){
      alert("xxx");
    }
  }
}

I am not getting this at all. This js file uses namespaces also. Help me underst开发者_JS百科anding this.


What that code does is define a single variable named fun1.

The value is an anonymous function with one parameter.

Calling the function would return an anonymous object with a .fun2 property, which points to another anonymous function.

Calling that function would trigger the alert:

 fun1(0).fun2(); // triggers alert("xxx")
0

精彩评论

暂无评论...
验证码 换一张
取 消