The answer to this question: What is the initial value of a JavaScript function's prototype property?
has this sentence:
The initial value
Javascript doesn't use classical inheritance, it uses prototypal inheritance where everything is an "Object" and inheritance is accomplished by cloning, for example:
var myPrototype = function() {
var privateMember = "I am private";
var publicMember = "I am public";
var publicMethod = function () {
alert(privateMember);
}
return {
publicMember = publicMember,
publicMethod = publicMethod
}
}
var myInstace = new myPrototype();
myInstance.publicMethod();
here myInstance
can be said to be an "instance of" myPrototype
, but in reality what happened is by using the new
keyword you cloned myPrototype
to create myInstance
.