ES6 class test
ES6 class test
by weiming le
Babel + JSX
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ',' + this.y + ')';
}
showInfo() {
console.log(this.x + ',' + this.y);
}
}
var p1 = new Point(1, 2);
console.log(p1, p1.showInfo());
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
}
var cp1 = new ColorPoint(10, 10, 'red');
console.log(cp1);
console.log(Point.prototype.constructor, Point.prototype);
console.log(ColorPoint.prototype, ColorPoint.prototype.__proto__, Point.prototype, Point.prototype.__proto__);
//console.log(Object.keys(Point.prototype));
console.log(Object.getOwnPropertyNames(Point.prototype));
class MyArray extends Array {
constructor(...args) {
super(...args);
}
}
var arr = new MyArray();
arr.push(12);
console.log(arr, arr.length);