While delving into the world of Three.js framework and in search of an efficient JavaScript inheritance pattern, I decided to explore how it was implemented in Three.js itself. After studying it closely, I have gained a solid understanding of most aspects, except for certain methods like Vector3.
One particular aspect that puzzles me is why some methods are directly assigned to the prototype, while others are added using THREE.extend within the same "class". For example:
...
THREE.Vector3.prototype = {
setX: function ( x ) {
this.x = x;
return this;
},
...
};
//and then later in the same file
THREE.extend( THREE.Vector3.prototype, {
applyEuler: function () {...}(),
...
}
I am curious about the advantages of using extend rather than simply augmenting the prototype object.
Edit
This code snippet is extracted from the same file available at https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js My question is not focused on the differences between the two approaches, but rather on why extend is utilized immediately after defining the prototype. In other words, why not just do this:
...
THREE.Vector3.prototype = {
setX: function ( x ) {
this.x = x;
return this;
},
applyEuler: function () {...}(),
...
};