ECMA 6 http://es6-features.org/#BaseClassAccess
class Shape { β¦ toString () { return `Shape(${this.id})` } } class Rectangle extends Shape { constructor (id, x, y, width, height) { super(id, x, y) β¦ } toString () { return "Rectangle > " + super.toString() } } class Circle extends Shape { constructor (id, x, y, radius) { super(id, x, y) β¦ } toString () { return "Circle > " + super.toString() } }
ECMA 5
var Shape = function (id, x, y) { β¦ }; Shape.prototype.toString = function (x, y) { return "Shape(" + this.id + ")" }; var Rectangle = function (id, x, y, width, height) { Shape.call(this, id, x, y); β¦ }; Rectangle.prototype.toString = function () { return "Rectangle > " + Shape.prototype.toString.call(this); }; var Circle = function (id, x, y, radius) { Shape.call(this, id, x, y); β¦ }; Circle.prototype.toString = function () { return "Circle > " + Shape.prototype.toString.call(this); };
zloctb Feb 22 '17 at 13:24 2017-02-22 13:24
source share