NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# 获取原型对象的方法 >**获取原型对象的三个方法** >[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__) ```