多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 获取原型对象的方法 >**获取原型对象的三个方法** >[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__) ```