I'm working to refactor a large and undocumented JavaScript Library. One of the proposed refactorings is to implement constructors in the code as opposed to dynamically constructing an object. Example Below:
Instead of:
var myLibObj = new Object();
myLibObj.SomeProperty =
{
FooFunction: function(){/*Do Something Cool*/}
}
The proposed change:
function myLibObjConstructor(){
this.SomeProperty = {FooFunction: function(){/*Do Something Cool*/}}
return this;
}
var myLibObj = new myLibObjConstructor();
Is there any advantage to changing the code?