Method Chaining in OOP in JavaScript

It is possible to make methods callable one after another in a chain. To do this, each such method must return this. Let's try. Let's add the corresponding code to the setters of our class:

javascriptclass User {
  #name;
  #surn;

  setName(name) {
    this.#name = name;
    return this;
  }
  setSurn(surn) {
    this.#surn = surn;
    return this;
  }
  
  getName() {
    return this.#name;
  }
  getSurn() {
    return this.#surn;
  }
}

Now our setters can be called one after another, in a chain. Let's check. Let's create an object of our class:

javascriptlet user = new User;

Let's call our setters in a chain:

javascriptuser.setName('john').setSurn('smit');

Let's check that the property values ​​have changed:

javascriptconsole.log(user.getName());
console.log(user.getSurn());
Задание 1

Make the setters of the Employee class chainable.