I would like to know what's the difference between these notations :
function Forms (formSelector) {
this.id;
this.formSelector = formSelector;
}
Forms.prototype.getAll = function () { return $(this.formSelector) } // get all forms in a JQuery object
Forms.prototype.get = function () { return $(this.getAll()).get(this.id) }
And
function Forms (formSelector) {
this.id;
this.formSelector = formSelector;
this.getAll = function () { return $(this.formSelector) }
this.get = function () { return $(this.getAll()).get(this.id) }
}
Or even
function Forms (formSelector) {
this.id;
this.formSelector = formSelector;
this.getAll = $(this.formSelector);
this.get = $(this.getAll()).get(this.id);
}
I can even write something like this:
var Forms = {
constructor: function (formSelector) {
this.formSelector = formSelector;
return this.formSelector;
},
setId: function (id) { if (!isNaN(id) this.id = id; }
getAll: function () {
return $(Forms.constructor.formSelector); // this should work I think ?
}
}
This is so confusing to me, I don't quite get to figure out what's the best and more optimized way to write my objects, in terms of speed and clarity, and to encapsulate their methods and properties.
In any case, it seems that I can modify my properties by just stating something like:
var test = new Forms('.forms');
test.id = 10;
test.getAll = 'something';
// What I want is something like :
test.setId(10) // and test.id = X shouldn't work
Thanks!