G
G
gtir2020-05-08 00:51:43
JavaScript
gtir, 2020-05-08 00:51:43

How to write hello method using ES6 syntax?

function User(name) {
  this.name = name;
  this.hello = function () {                //метод hello
     console.log ("Мене зовут" + this.name);
   };
}

let userOne = new User("Вася");
let userSecond = new User("Саша");

userOne.hello();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Ivanov, 2020-05-08
@gtir

class User {
  constructor(name) {
    this.name = name;
  }
  
  hello() {  //метод hello
    console.log ("Мене зовут" + this.name);
  };
}

let userOne = new User("Вася");
let userSecond = new User("Саша");

userOne.hello();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question