Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active March 19, 2017 10:57
Show Gist options
  • Save kenmori/deb4d2516c6a69c51e5723c7ab3bf59f to your computer and use it in GitHub Desktop.
Save kenmori/deb4d2516c6a69c51e5723c7ab3bf59f to your computer and use it in GitHub Desktop.
【TypeScript】__extendsやnew __()は何をやっているか[JS]
//http://kenjimorita.jp/typescript__extends_new__
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Point = (function () {
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype.add = function (point) {
return new Point(this.x + point.x, this.y + point.y);
};
Point.prototype.log = function () {
console.log("here is Point");
};
return Point;
}());
var point = new Point(1, 1);
var Point3D = (function (_super) {
__extends(Point3D, _super);
function Point3D(x, y, z) {
_super.call(this, x, y);
this.z = z;
}
Point3D.prototype.add = function (point) {
var point2D = _super.prototype.add.call(this, point);
return new Point3D(point2D.x, point2D.y, this.z + point.z);
};
return Point3D;
}(Point));
var point3d = new Point3D(5, 10, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment