What’s the advantage of using a constructor function like so:
var MyLibrary = new function(){
var self = this;
self.MyLibrary = function(){
// init code
}
}
Instead of simply writing code inside the object?
var MyLibrary = new function(){
// init code
}
Neither of those are quite right, although the second one might work, but isn’t really an object, more like a singleton(but in a weird way). Here’s an example of a class with a constructor:
Now to use this class:
You can also define a class by saving the ‘constructor’ to a var using anonymous functions instead of named functions: