I am working on a reorganization of a large and undocumented JavaScript library. One of the proposed refactoring is the implementation of constructors in code, rather than the dynamic construction of an object. Example below:
Instead:
var myLibObj = new Object();
myLibObj.SomeProperty =
{
FooFunction: function(){}
}
Proposed Change:
function myLibObjConstructor(){
this.SomeProperty = {FooFunction: function(){}}
return this;
}
var myLibObj = new myLibObjConstructor();
Is there any advantage to changing the code?
source
share