0

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 understanding this.

1 Answer 1

4

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")
Sign up to request clarification or add additional context in comments.

1 Comment

You could also omit the unused argument to fun1: fun1().fun2();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.