Background
Working with OOP-style in JavaScript, by creating pseudo-classes using objects. From examples and walkthroughs online, I'd been under the impression that we need to set up an object, then attach function to that object's prototype object.
However, I have been playing around today and tried attaching a function directly to the object itself. From testing, I can't find any behavioral differences. Simplified example of both ways below:
Version 1
var Class = function( params ) {
}
Class.prototype.getData = function() {
return _data;
};
Version 2
var Class = function( params ) {
this.getData = function() {
return _data;
}
}
Question
What is the difference, if any, between these two implementations?