hon9g / TIL

Note taking on issue tab
https://github.com/hon9g/TIL/issues
1 stars 1 forks source link

JavaScript: class in ES6 #5

Open hon9g opened 5 years ago

hon9g commented 5 years ago

INDEX

# title link
1 Create Class and Object go
2 Static Property and Static Method go
3 Getter and Setter go
hon9g commented 4 years ago

Create Class and Object

console.log(cat); // Cat {name: "Fluffy", color: "White"} console.log(cat.speak()); // Fluffy is Mewwww


- `type of` class Cat
```JavaScript
console.log(typeof Cat); // function
hon9g commented 4 years ago

Static Property

Static Method

hon9g commented 4 years ago

Getter

class Employee {
  constructor(id) {
    this._id = id;
  }
  // This is the getter
  get id() {
    return this._id;
  }
}
let h = new Employee(9999);

Setter

class Employee {
  constructor(id) {
    this._id = id;
  }
  get id() {
    return this._id;
  }
  // This is the setter
  set id(value) {
    this._id = value;
  }
}