Skip to content

Commit f8fec73

Browse files
committed
example 2
1 parent d2334db commit f8fec73

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

classical-inherit.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,24 @@ var object = new Child();
1919

2020
console.log(object.wasBornParent, object.isChildClassUsed); // true true
2121

22+
23+
// classical inherit #2
24+
25+
26+
function Parent (name) {
27+
this.name = name || 'vlad';
28+
}
29+
30+
31+
32+
function Child () {
33+
this.surname = 'khvostov';
34+
// Call parent constructor like method for this object
35+
// minus: parent prototype is lost
36+
Parent.apply(this, arguments)
37+
}
38+
39+
var object = new Child('Alex');
40+
41+
console.log(object) // Child {surname: "khvostov", name: "Alex"}
42+

0 commit comments

Comments
 (0)