ES6 Class Ok
ES6 Class Ok
'use strict';
class StaticMem {
static disp() {
console.log("Static Function called") ;
}
}
StaticMem.disp(); //invoke the static method
$node main.js
Static Function called
//creating an instance
var polyObj = new Polygon(10,20);
polyObj.test();
$node main.js
The height of the polygon: 10
The width of the polygon: 20
Kế thức lớp
'use strict';
class Shape {
constructor(a) {
this.Area = a;
}
}
class Circle extends Shape {
disp() {
console.log("Area of the circle: "+this.Area);
}
}
var obj = new Circle(223);
obj.disp();
$node main.js
Area of the circle: 223
Ghi đè phương thức
'use strict' ;
class PrinterClass {
doPrint() {
console.log("doPrint() from Parent called… ");
}
}
class StringPrinter extends PrinterClass {
doPrint() {
console.log("doPrint() is printing a string…");
}
}
var obj = new StringPrinter();
obj.doPrint();
$node main.js
doPrint() is printing a string…