Last active
July 22, 2021 07:47
-
-
Save stevenocchipinti/01c5ade4bcf8f3a213f21a10cb945904 to your computer and use it in GitHub Desktop.
A simple demonstration of classes in es6
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
// | |
// Person.js | |
// | |
// This is a simple Person class. | |
// | |
// It doesn't do much, but it demonstrates the use of ES6 classes. Note that | |
// this code will most likely not work in old browsers directly. To 'compile' | |
// this down to the more widely accepted ES5, you could use Babel. | |
// | |
class Person { | |
constructor(name) { | |
this.name = name; | |
} | |
say(text) { | |
console.log(`${this.name} says: ${text}`); | |
} | |
} | |
const bob = new Person('Bob'); | |
bob.say("Hello World"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment