I have the following code in javascript, and I am unclear on the underlying functionality of the following prototyping:
function TestClass()
{
}
var externalFunction = function() {
console.log("hit the function defined internally");
};
Object.defineProperty(TestClass.prototype, "myFunction", {
enumerable: false,
writable: false,
value: externalFunction
});
TestClass.prototype.myFunction2 = function() {
console.log("hit the function defined on the prototype");
}
var tc = new TestClass();
var tc2 = new TestClass();
console.log(tc.myFunction === tc2.myFunction);
console.log(tc.myFunction2 === tc2.myFunction2);
Are either of myFunction
or myFunction2
re-created whenever a new TestClass()
is defined, or will the new TestClass()
contain pointers to the original myFunction
and myFunction2?