Last active
August 31, 2017 13:32
-
-
Save colinrotherham/8fcf7845a7a2847876ced463843f4435 to your computer and use it in GitHub Desktop.
Example ES6 class
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
import Etiquette from './lib/etiquette'; | |
import message from './lib/message'; | |
class Greeter extends Etiquette { | |
constructor (config) { | |
super(); | |
this.intro = config.intro; | |
this.name = config.name; | |
} | |
message (greeting) { | |
console.log(`${greeting} ${this.name}`); | |
} | |
async hello () { | |
const greeting = await message.waitUntilArrive(); | |
this.message(greeting); | |
} | |
async goodbye () { | |
const farewell = await message.waitUntilExit(); | |
this.message(farewell); | |
} | |
} | |
const example = new Greeter({ | |
intro: 'Hello', | |
name: 'Colin Rotherham' | |
}); | |
try { | |
example.hello(); | |
example.goodbye(); | |
} catch (err) { | |
console.err(err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment