// console.log(null.proto) // Cannot read property ‘proto’ of null
console.log(Object.prototype.proto); // null
// 原型对象的作用:继承,
// 1:面向对象开发(抽象)
// 继承例子
var perso = function (name) {
this.name = name;
};
// 函数原型对象下 api 原则上;必须指向 【构造对象】
perso.prototype.getName = function () {
return this.name;
};
perso.prototype.setAge = function (age) {
this.age = age;
};
var obj = {
name: “余非”,
};
var zc = new perso(“周超”);
var res = zc.getName();
zc.setAge.call(obj, 21); // 修改了 this 指向
console.log(zc);
console.log(res);
// zc 的 proto 指向的 perso的prototype
console.log(zc.proto === perso.prototype);
// console.log(perso.prototype.proto === Object.prototype);
console.log(zc.proto.proto === Object.prototype, “--------”);
// console.log(Object.prototype.proto); // null
// 原型链
console.log(
zc.proto.proto.proto === Object.prototype.proto
); // null
// 找到null 停止
// 继承:被继承的属性都可以被继承者直接使用
// console.log(zc.valueOf) // zc 直接访问 Object.prototype中属性
// 谈谈你对js 原型的认识
// 原型链 继承。
JS原型与原型链解析
10万+

被折叠的 条评论
为什么被折叠?



