Skip to content

Instantly share code, notes, and snippets.

@floydawong
Last active February 28, 2018 14:19
Show Gist options
  • Save floydawong/e35ba4619ea3d5e9c18e3f1acbe0c317 to your computer and use it in GitHub Desktop.
Save floydawong/e35ba4619ea3d5e9c18e3f1acbe0c317 to your computer and use it in GitHub Desktop.
TS_class
class Shape {
width: number;
height: number;
area: number;
color: string;
name: string;
constructor(name: string, width: number, height: number) {
this.name = name;
this.area = width * height;
this.color = "pink";
this.width = width;
this.height = height;
};
shoutout() {
return "I'm " + this.color + " " + this.name + " with an area of " + this.area + " cm squared.";
}
}
var square = new Shape("square", 30, 30);
console.log(square.shoutout());
console.log('Area of Shape: ' + square.area);
console.log('Name of Shape: ' + square.name);
console.log('Color of Shape: ' + square.color);
console.log('Width of Shape: ' + square.width);
console.log('Height of Shape: ' + square.height);
class Shape3D extends Shape {
volume: number;
constructor(public name: string, width: number, height: number, length: number) {
super(name, width, height);
this.volume = length * this.area;
};
shoutout() {
return "I'm " + this.name + " with a volume of " + this.volume + " cm cube.";
}
superShout() {
return super.shoutout();
}
}
var cube = new Shape3D("cube", 30, 30, 30);
console.log(cube.shoutout());
console.log(cube.superShout());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment