开发者

JavaScript anonymous function syntax

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜