I'm trying to use module pattern with the following code:
(function(elements) {
elements.Textbox = function() {
this.properties = elements.defaultProperties.textboxProperties;
}
elements.Textbox.prototype = {
setSize: function(size) {
this.properties.size = size;
},
getProperties: function() {
return this.properties;
},
getSize: function() {
return this.properties.size;
}
}
}(app.elements || {}));
And trying to create and modify objects like so
var textbox1 = new app.elements.Textbox();
var textbox2 = new app.elements.Textbox();
textbox2.setSize({
width: 300,
height: 100
});
But this causes both textboxes to endup with same height and width. I'm new to using Module pattern with Constructor. If I take out Textbox, and then do
var textbox1 = new Textbox();
var textbox2 = new Textbox();
textbox2.setSize({
width: 300,
height: 100
});
This works fine. I'm somewhat misunderstood about this, so thanks in advance for help and clarification.
Edit: I've looked at many SO questions, including: Javascript: Module Pattern vs Constructor/Prototype pattern? and they've all been very helpful.