Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created February 3, 2019 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitfishxyz/86a343e0af8efd07a8f558a477a84d89 to your computer and use it in GitHub Desktop.
Save bitfishxyz/86a343e0af8efd07a8f558a477a84d89 to your computer and use it in GitHub Desktop.
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