标签:问题 on() -- object 函数 ons 实例 prototype ==
function Person(age){
this.age=10;
//在构造函数中的方法
}
//人的原型对象的方法
Person.prototype.eat=function(){
console.log("人的吃");
}
//学生的构造函数
function Student(){
}
Student.prototype.sayHi=function(){
console.log("学生hi");
};
//学生的原型,指向了一个人的实例对象
Student.prototype=new Person(10);
var stu=new Student();
stu.eat();
console.log(stu.age);
stu.sayHi();
function Person(age){
this.age=10;
//在构造函数中的方法
}
//人的原型对象的方法
Person.prototype.eat=function(){
console.log("人的吃");
}
var per =new Person(10);
//原型对象指向了哪里
console.log(per.__proto__==Person.prototype);
console.log(per.__proto__.__proto__== Person.prototype.__proto__);
console.log(Person.prototype.__proto__==Object.prototype);
console.log(Object.prototype.__proto__);
//如果原型指向改变了,那么就应该在原型改变之后添加原型方法
function Person(age){
this.age=age;
}
//指向改变了,
//先添加原型的方法
Person.prototype.eat=function(){
console.log("人在吃");
}
//学生构造函数
function Student(sex){
this.sex=sex;
}
//学生的原型中添加方法---先在原型中添加
//改变了原型对象的指向
Student.prototype.sayHi=function(){
console.log("你好啊");
}
Student.prototype=new Person(10);
var stu=new Person();
stu.eat();
stu.sayHi();
//原型对象实例对象
function Person(age,sex){
this.age=age;
this.sex=sex;
}
//
Person.prototype.sex="女";
var per=new Person(10,"男");
标签:问题 on() -- object 函数 ons 实例 prototype ==
原文地址:https://www.cnblogs.com/liushisaonian/p/9459609.html