//создание функции-конструктора Human со свойствами и методами
function Human(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
this.speak = function() {
return "My name is " + this.name + ". I'm " + this.age + " years old, and I can speak";
}
this.walk = function() {
return "This.name " + "can walk";
}
}
//создание 4х экземляров Human
var john = new Human('John', 22, 'male');
var tom = new Human('Tom', 25, 'male');
var alice = new Human('Alice', 21, 'female');
var betty = new Human('Betty', 23, 'female');
//добавление свойств и методов на уровне экземпляра
john.height = 174;
john.dance = function() {
return "John can dance";
}
tom.drive = function() {
return "Tom can drive";
}
tom.height = 190;
alice.cliffDive = function() {
return "Alice can cliffdive";
}
alice.height = 180;
betty.cook = function() {
return "Betty can coook";
}
betty.height = 165;