I've seen a lot of this...
function myObject(data) {
var myData = data;
}
myObject.prototype.doSomething = function () {
alert("I did something!");
}
but the intellisense on Visual Studio gives me a .constructor for functions, which would lead me to believe this would be correct...
function myObject() {
var myData;
this.constructor = function(data) {
myData = data;
}
this.doSomething = function() {
alert("I did something!");
}
}
I like the encapsulation of the second method, but almost everyone uses the ".prototype". Is there any reason for doing this in particular or is it ok to encapsulate all the classes methods like this.