Commit a7e7d5d4 authored by Jon Tavernier's avatar Jon Tavernier

add classes

parent 4070c1df
<!DOCTYPE HTML>
<html>
<body>
<p>Before the script...</p>
<script>
"use strict";
// Class Declaration
// Can also be created via expression.
// such as let City = class {...}
class City {
constructor(name, state) {
// will call the setter
this._name = name;
this.state = state;
}
// getter for name
get name() {
return this._name;
}
// setter for name
set name(value) {
if (value.length < 4) {
console.log("Name is too short.");
return;
}
this._name = value;
}
// avoid including "function" before method name
sayWelcomeGuest(guest_name) {
return `Welcome to ${this.name}, ${guest_name}!`;
}
}
let chicago = new City("Chicago", "IL");
console.log(chicago.name);
console.log(chicago.sayWelcomeGuest("Bugs"));
// inheritance is supported too via extends: https://javascript.info/class-inheritance
</script>
<p>...After the script.</p>
</body>
</html>
\ No newline at end of file
......@@ -20,6 +20,7 @@
'08_destructuring.html',
'09_date_time.html',
'10_json.html',
'11_classes.html',
];
for (let href of tutorials){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment