Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active March 19, 2017 10:58
Show Gist options
  • Save kenmori/827295cd17d31eb35719cb825c4aca89 to your computer and use it in GitHub Desktop.
Save kenmori/827295cd17d31eb35719cb825c4aca89 to your computer and use it in GitHub Desktop.
【TypeScript】__extendsやnew __()は何をやっているか
class Point {
x: number;
y: number;
constructor(x, y){
this.x = x;
this.y = y;
}
add(point) {
return new Point(this.x + point.x, this.y + point.y);
}
log(): void{
console.log("here is Point");
}
}
var point = new Point(1, 1);
class Point3D extends Point {
z:number;
constructor(x, y, z){
super(x, y);
this.z = z;
}
add(point){
var point2D = super.add(point);
return new Point3D(point2D.x, point2D.y, this.z + point.z);
}
}
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