0% found this document useful (0 votes)
10 views2 pages

ES6 Class Ok

The document provides examples of JavaScript class features including static methods, instance methods, inheritance, and method overriding. It demonstrates how to define and invoke static functions, access instance properties, extend classes, and override methods in subclasses. Each example includes code snippets and their corresponding output when executed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

ES6 Class Ok

The document provides examples of JavaScript class features including static methods, instance methods, inheritance, and method overriding. It demonstrates how to define and invoke static functions, access instance properties, extend classes, and override methods in subclasses. Each example includes code snippets and their corresponding output when executed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Từ khóa Static

'use strict';
class StaticMem {
static disp() {
console.log("Static Function called") ;
}
}
StaticMem.disp(); //invoke the static method
$node main.js
Static Function called

Truy cập hàm


'use strict' ;
class Polygon {
constructor(height, width) {
this.h = height;
this.w = width;
}
test() {
console.log("The height of the polygon: ", this.h) ;
console.log("The width of the polygon: ",this. w) ;
}
}

//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…

You might also like