账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    javascript - 修改__proto__为什么prototype也变了?
    93
    0

    看代码

    function Parent() {
      this.name = "zhangsan";
      this.list = [];
    }
    function Child() {
      Parent.call(this);
      this.age = 18;
    }
    Child.prototype.__proto__=Parent.prototype;
    Child.prototype.contructor = Child;

    上面是继承的常见写法,默认情况下Child.prototype.__proto__应该指向Object.prototype,为了实现child是继承parent的,所以修改原型链
    Child.prototype.__proto__=Parent.prototype;
    到这我是理解的。

    但是为什么修改了__proto__,Child.prototype也变成了Parent呢?__proto__不应该是prototye的一个属性吗?prototype的指向不应该还是Child吗,只是proto指向Parent来实现继承?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版