Rubik's cube 5x5x5 edgeswap added.
[zzandy.git] / inheritance.js
blob0c8d4df1032367fe58ff4f1aadbf0ce2e273cc7b
1 function Base(x, y)\r
2 {\r
3     this.x = x;\r
4     this.y = y;\r
5     console.log('Base here', this.x, this.y);\r
6 }\r
7 \r
8 Base.prototype.echo = function()\r
9 {\r
10     console.log('Base echo here', this.x, this.y);\r
11 };\r
13 function Derived(x, y, z)\r
14 {\r
15     console.log('calling base');\r
16     Base.call(this, x, y);\r
17     console.log('base called');\r
18     this.z = z;\r
19     console.log('Derived here', this.x, this.y, this.z);\r
20 }\r
22 Derived.prototype = new Base; // Base constructor null null is called\r
23 Derived.prototype.base = Base.prototype;\r
25 Derived.prototype.echo = function()\r
26 {\r
27     this.base.echo.call(this);\r
28     console.log('Derived echo here', this.x, this.y, this.z);\r
29 };\r
31 var t = new Derived(10, 20, 30);\r
32 console.log('init complete');\r
33 t.echo();\r
34 Derived.constructor.toSource();\r
36 console.log(t instanceof Base); // true\r
37 console.log(t instanceof Derived); // true\r