ES6 static menber
[code]
class Tripple {
static tripple(n) {
n = n || 1;
return n * 3;
}
}
class BiggerTripple extends Tripple {
static tripple(n) {
return super.tripple(n) * super.tripple(n);
}
}
console.log(Tripple.tripple());//3
console.log(Tripple.tripple(6));//18
console.log(BiggerTripple.tripple(3));//81
[/code]
Class inheritance
[code]
class Shape {
constructor(id,x, y){
this.id = id;
this.move(x,y);
}
move(x, y){
this.x = x;
this.y = y;
}
}
class Rectangle extends Shape {
constructor(id, x, y, width, height){
super(id, x, y);
this.width = width;
this.height = height;
}
getWidth(){
return this.width * this.height
}
}
class Radius extends Shape {
constructor(id, x, y, radius){
super(id, x, y);
this.radius = radius;
}
getRudius(){
return 10 * this.radius;
}
}
var rec = new Rectangle(1,10,12,100,50);
console.log(rec.getWidth());
var radius = new Radius(2,20,12,50);
console.log(radius.getRudius());
[/code]