What is the best way to build constructors in JavaScript using object literal notation?
var myObject = {
funca : function() {
//...
},
funcb : function() {
Make the object a function, like this:
var myObject = function(arg1){
this.funca = function(){
//...
};
this.funcb = function(){
//...
};
this.constructor = function(obj){
alert('constructor! I can now use the arg: ' + obj.name);
};
this.constructor(arg1);
};
// Use the object, passing in an initializer:
var myVar = new myObject({ name: 'Doug'});