The snippets #1 and #3 do the same thing. The benefit of the first is that you don't need to repeat Class.prototype.
, and might even define static "class-local" variables. However, the usage of .call
is unusal, mostly a simple parameter named proto
or so is used:
function Class() {...}
(function(p) {
p.method1 = function() {...};
p.method2 = function() {...};
}(Class.prototype));
The difference between this assignment of individual properties and snippet #2 is covered in Defining a Javascript prototype.
What snippet #4 does is a little unclear do to your use {...}
. However, Object.create
is usually used for inheritance between classes.
The difference between prototype methods and instance-specific methods (snippet #5) is well-covered in Use of 'prototype' vs. 'this' in JavaScript?.