Created
March 8, 2017 00:39
-
-
Save Wikiko/b19dbb0cafb084016cceedace72b94f2 to your computer and use it in GitHub Desktop.
Comparação ecmas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | |
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var Point = function () { | |
function Point(x, y) { | |
_classCallCheck(this, Point); | |
this.x = x; | |
this.y = y; | |
} | |
_createClass(Point, [{ | |
key: 'toString', | |
value: function toString() { | |
return '(' + this.x + ', ' + this.y + ')'; | |
} | |
}]); | |
return Point; | |
}(); | |
var ColorPoint = function (_Point) { | |
_inherits(ColorPoint, _Point); | |
function ColorPoint(x, y, color) { | |
_classCallCheck(this, ColorPoint); | |
var _this = _possibleConstructorReturn(this, (ColorPoint.__proto__ || Object.getPrototypeOf(ColorPoint)).call(this, x, y)); | |
_this.color = color; | |
return _this; | |
} | |
_createClass(ColorPoint, [{ | |
key: 'toString', | |
value: function toString() { | |
return _get(ColorPoint.prototype.__proto__ || Object.getPrototypeOf(ColorPoint.prototype), 'toString', this).call(this) + ' in ' + this.color; | |
} | |
}]); | |
return ColorPoint; | |
}(Point); | |
var cp = new ColorPoint(25, 8, 'green'); | |
cp.toString(); // '(25, 8) in green' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
toString() { | |
return '(' + this.x + ', ' + this.y + ')'; | |
} | |
} | |
class ColorPoint extends Point { | |
constructor(x, y, color) { | |
super(x, y); | |
this.color = color; | |
} | |
toString() { | |
return super.toString() + ' in ' + this.color; | |
} | |
} | |
let cp = new ColorPoint(25, 8, 'green'); | |
cp.toString(); // '(25, 8) in green' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment