Created
August 24, 2021 09:54
-
-
Save ardeshireshghi/583deeef49b70d45fdb9fea0044c1d84 to your computer and use it in GitHub Desktop.
This file contains 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
// Old school classic inheritence | |
function Shape(name) { | |
this.name = name; | |
} | |
Shape.prototype.getName = function() { | |
return this.name; | |
} | |
function Square(width, height) { | |
Shape.call(this); | |
this.width = width | |
this.height = height | |
} | |
Square.prototype = new Shape('square') | |
// Mid-school | |
function Shape(name) { | |
this.name = name; | |
} | |
Shape.prototype.getName = function() { | |
return this.name; | |
} | |
function Square(width, height) { | |
Shape.call(this, 'square'); | |
this.width = width | |
this.height = height | |
} | |
Square.prototype = Object.create(Shape.prototype) | |
// Late-school | |
class Shape { | |
constructor(name) { | |
this.name = name | |
} | |
getName() { | |
return this.name | |
} | |
} | |
class Square extends Shape { | |
constructor(width, height) { | |
super('square') | |
this.width = width | |
this.height = height | |
} | |
} | |
// State of the art - TS | |
class Shape { | |
constructor(public name: string) {} | |
getName(): string { | |
return this.name | |
} | |
} | |
class Square extends Shape { | |
constructor(public width: number, public height: number) { | |
super('square') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment