got this function:
function Something(name){
this.name = name;
}
var createSomething = (function() {
function F(args) {
return Something.apply(this, args);
}
F.prototype = Something.prototype;
return function() {
return new F(arguments);
}
})();
var x = createSomething('abc');
Why does createSomething have to be a self-invoking function?
I noticed when leaving the invoking brackets ()
, x will just be empty. But why?
It invokes "unasked" at the initialization of the javascript and then runs again once "asked" for. But what's the point of the first run? Does it straight assign the "this" correctly, or what's the point of use?