Created
January 10, 2019 09:19
-
-
Save 2color/316ab17bcf1f6aa064de73653bc9df45 to your computer and use it in GitHub Desktop.
Default method parameters can access object properties
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 Person { | |
constructor (name) { | |
this.name = name | |
this.defaultSalultation = 'Dr.' | |
} | |
sayHello (salutation = this.defaultSalultation) { | |
return `Hello ${salutation} ${this.name}` | |
} | |
} | |
const dr1 = new Person('James Baldwin') | |
console.log(dr1.sayHello('The One and Only Mr.')) // Hello The One and Only Mr. James Baldwin | |
const dr2 = new Person('David Deutsch') | |
console.log(dr2.sayHello()) // Hello Dr. David Deutsch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment