function Person(name, age) {
this.name = name
this.age = age
}
let p1 =new Person('张三', 10)
let p2 =new Person('李四', 20)
let p3 =new Person('王五', 40)
console.log(p1, p2, p3)
function Person(name, age) {
this.name = name
this.age = age
this.dine = function () {
console.log('吃饭');
}
}
let p1 = new Person('张三', 10)
let p2 = new Person('李四', 20)
let p3 = new Person('王五', 40)
console.log(p1, p2, p3)
console.log(p2.dine == p1.dine);
let obj = {
f1 : function () {
console.log('吃饭');
}
}
function Person(name, age) {
this.name = name
this.age = age
this.dine = obj.f1();
}
let p1 = new Person('张三', 10)
let p2 = new Person('李四', 20)
let p3 = new Person('王五', 40)
console.log(p1, p2, p3)
console.log(p2.dine == p1.dine);
function Person(name, age) {
this.name = name
this.age = age
}
Person.prototype.dine = function () {
console.log('吃饭');
}
let p1 = new Person('张三', 10)
let p2 = new Person('李四', 20)
let p3 = new Person('王五', 40)
console.log(p1, p2, p3)
console.log(p2.dine == p1.dine);