This is one thing I was wondering for a long time. But first example code for both
Type A
var JavaScriptClass = function () {
};
JavaScriptClass.prototype = {
myMethodOne: function() {
},
myMethodTwo: function() {
}
};
Type B
var JavaScriptClass = function () {
};
JavaScriptClass.prototype.myMethodOne = function(){
};
JavaScriptClass.prototype.myMethodTwo = function(){
};
I saw both in lots of tutorials, examples and libraries (subjective Type A in the older ones).
For me it is more comfortable to use Type A especially in large classes, because you have to write less code. But as I know the compiler of coffeescript compiles the Class
statement to Type B.
Is there a considerable difference between Type A and B (e.g. performance, advantages with inheritance, or better IDE support) or is this only a "coding style" thing?