AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
# 获取原型对象的方法 >**获取原型对象的三个方法** >[success] >1、构造函数.prototype >2、实例化对象.__proto__ > 3、Object.getPrototypeOf(实例化对象) Object.getPrototypeOf(per1) > 4.Object.setPrototypeOf(实例化对象,该对象的新原型) ```javascript //构造函数 function Person(name,age,sex) { this.name = name;//属性都添加在构造函数里面 this.age = age; this.sex = sex; } //方法都加在原型上 Person.prototype.sayHi = function () { console.log("我是原型上面方法"); }; //实例化对象 var per1 = new Person("ZS",18,1); console.log(per1); //获取原型对象 console.log(Person.prototype); console.log(per1.__proto__); console.log(Object.getPrototypeOf(per1)); //比较一下 console.log(Person.prototype == per1.__proto__); //true console.log(Person.prototype == Object.getPrototypeOf(per1)); //trur console.log(Object.getPrototypeOf(per1) == per1.__proto__); //true // 修改原型 var b = new Object(); var Bar = function() {} Object.setPrototypeOf(b,Bar.__proto__) ```