Constructor
class Dog {
constructor(name){
this._name = name;
this._behavior = 0;
}
}
Dog is the name of our class. By convention, we capitalize and CamelCase class names.
JavaScript will invoke the constructor() method every time we create a new instance of our Dog class.
This constructor() method accepts one argument, name.
Inside of the constructor() method, we use the this keyword. In the context of a class, this refers to an instance of that class. In the Dog class, we use this to set the value of the Dog instance’s name property to the name argument.
Under this.name, we create a property called behavior, which will keep track of the number of times a dog misbehaves. The behavior property is always initialized to zero.
Instance of class
let Halley = new Dog(name, behavior)
Methods
class Dog {
constructor(name){
this._name = name
}
changeName(newName){
return this._name = newName
}
}