var speak = function () {
console.log(this.sound + "! Меня зовут " + this.name + "!")
}
var cat = {}
cat.sound = "Мяу"
cat.name = "Мурзик"
cat.age = 3
cat.speak()
var speak = function () {
console.log(this.sound + "! Меня зовут " + this.name + "!")
}
var cat = {}
cat.sound = "Мяу"
cat.name = "Мурзик"
cat.age = 3
cat.speak()
// cat.speak и остается необъявленным undefined
.....
cat.speak = speak
cat.speak()
Object.prototype.speak = speak
dog = {sound: 'gav', name: 'Psina'}
dog.speak()
class Cat {
constructor(name, sound, age) {
this.name = name;
this.sound = sound;
this.age = age;
}
speak() {
console.log(`${this.sound}! Меня зовут ${this.name}!`);
}
}
const murzik = new Cat('Мурзик', 'мяу', 3);
murzik.speak();