I am trying to create a javascript library. There are two apparent ways of doing this.
The first way uses new:
var myLib = new function(){
this.square = function(x){
return x*x;
};
}();
The other way is to return an object:
var myLib = function(){
function square(x){
return x*x;
};
return {square:square};
}();
Is one way preferable to the other, or is it a matter of personal preference.