Created
February 3, 2019 06:34
-
-
Save bitfishxyz/86a343e0af8efd07a8f558a477a84d89 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
class PersonClass{ | |
constructor(name, age){ | |
this.name = name | |
this.age = age | |
} | |
getName(){ | |
return this.name | |
} | |
} | |
class AdultClass extends PersonClass{ | |
constructor(name, age, job) { | |
super(name, age) | |
this.job = job | |
} | |
getJob(){ | |
return this.job | |
} | |
} | |
function PersonFunc(name, age){ | |
this.name = name | |
this.age = age | |
} | |
PersonFunc.prototype.getName = function(){ | |
return this.name | |
} | |
function AdultFunc(name, age, job){ | |
PersonFunc.call(this, name, age) | |
this.job = job | |
} | |
AdultFunc.prototype.getJob = function(){ | |
return this.name | |
} | |
Object.setPrototypeOf(AdultFunc.prototype, PersonFunc.prototype) | |
var a1 = new AdultClass('Bob', 18, 'programer') | |
console.log(a1) | |
console.log(a1.getJob()) | |
var a2 = new AdultFunc('Bob', 18) | |
console.log(a2) | |
console.log(a2.getName()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment