Hello!
I got recently intrigued with JavaScript's prototype-based
object-orientation.
However, I still don't understand the mechanism clearly.
[Q1]
What's the difference between the following two?
(1)
function C(){
this.name = "Unknown"
}
(2)
function C(){
}
C.prototype.nam e = "Unknown"
[Q2]
There's no notion of Class in JavaScript and everything is an object.
How many objects are created in the following code including the
objects implicitly created in the behind?
function C(){
}
function D(){
}
D.prototype = new C
var obj = new D
[Q3]
I saw some codes like "this.base = SomeClass".
When is it needed?
Is it different from ClassName.proto type = new ParentClassName ?
[Q4]
What's the difference between prototype and __proto__?
Thanks in advance.
Sam
I got recently intrigued with JavaScript's prototype-based
object-orientation.
However, I still don't understand the mechanism clearly.
[Q1]
What's the difference between the following two?
(1)
function C(){
this.name = "Unknown"
}
(2)
function C(){
}
C.prototype.nam e = "Unknown"
[Q2]
There's no notion of Class in JavaScript and everything is an object.
How many objects are created in the following code including the
objects implicitly created in the behind?
function C(){
}
function D(){
}
D.prototype = new C
var obj = new D
[Q3]
I saw some codes like "this.base = SomeClass".
When is it needed?
Is it different from ClassName.proto type = new ParentClassName ?
[Q4]
What's the difference between prototype and __proto__?
Thanks in advance.
Sam
Comment