This file contains hidden or 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
let Person = class { | |
constructor(name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
speak() { | |
return `Hello, my name is ${this.name} and I am ${this.age}` | |
} | |
} |
This file contains hidden or 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
let victor = new Person('Victor', 23); | |
console.log(victor.speak()); |
This file contains hidden or 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
let Work = class extends Person { | |
constructor(name, age, work) { | |
super(name, age); | |
this.work = work | |
} | |
getInfo() { | |
return `Hey! It's ${this.name}, I am age ${this.age} and work for ${this.work}.` | |
} | |
} |
This file contains hidden or 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
let Person = function(name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
Person.prototype.speak = function() { | |
return `Hello, my name is ${this.name} and I am ${this.age}` | |
} | |
let victor = new Person(`Victor`, 23) |
This file contains hidden or 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
let Work = function(name, age, work) { | |
Person.call(this, name, age); | |
this.work = work; | |
} |
This file contains hidden or 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
Object.setPropertyOf(Work.prototype, Person.prototype); |
This file contains hidden or 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
Work.prototype.getInfo = function() { | |
return `Hey! It's ${this.name}, I am age ${this.age} and work for ${this.work}.` | |
} | |
let alex = new Work("Alex", 40, 'SessionStack'); | |
console.log(alex.getInfo()); |
This file contains hidden or 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
const sayHello = function(name) { | |
return `Hello ${name}`; | |
} | |
sayHello('Victor'); | |
# => Hello Victor |
This file contains hidden or 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
let surname = 'Jonah'; | |
const sayHi = function() { | |
return `Hi ${surname}`; | |
} |
This file contains hidden or 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
const sayHi = function(surname) { | |
return `Hi ${surname}`; | |
} |
OlderNewer