Answer the question
In order to leave comments, you need to log in
Why is there a double bracket for function expression?
Tell me why this code to execute alert ( Jsfiddle ):
var newclass = new Classname();
newclass.method.init();
function Classname () {
this.method = function () {
return {
init: function () {
alert();
}
}
}()
}
var newclass = new Classname();
newclass.method.init();
function Classname () {
this.method = function () {
return {
init: function () {
alert();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
In the first case, it this.method
will be the result of executing the function:
{
init: function () {
alert();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question