ES6 classes
by Dru Dro
JavaScript
class Person {
constructor(name, age, sex) {
this.name = name;
this.sex = sex;
this.age = age;
}
speak() {
alert(`Hello, my name is ${this.name}, i'm ${this.age}-years old ${this.sex}`);
}
}
class Employee extends Person {
constructor(name, age, sex, job, salary) {
super(name, age, sex);
this.salary = salary;
this.job = job;
}
askMore() {
const newS = prompt('I VONT MOR MANI! NOW!');
this.salary = newS;
}
}
const vladimir = new Employee('Vladimir', 56, 'male', 'janitor', 14000);
vladimir.speak();
alert(vladimir.salary + ': ' + vladimir.job);
vladimir.askMore();
alert(vladimir.salary);