原型继承

 function A() {
    this.x = 100
  }
  A.prototype.getX = function () {
    console.log(this.x)
  }

  function B() {
    this.y = 200
  }
  // 继承的话
  B.prototype = new A; //A的实例既有私有属性也有公有属性
  B.prototype.constructor = B;

上面是普通方法

父类的私有和公有属性都变成子类的公有属性

下面的call继承,父类的所有方法都变成子类的私有属性

// ->calll继承:把父类私有的属性和方法 克隆一份一样的作为子类私有的属性
  function A() {
    this.x = 100;
  }
  A.prototype.getX = function () {
    console.log(this.x)
  }
  function B() {
    // this.x =200;
    A.call(this) // A.call(n) 把A执行让A中的this变成n,
  }
  // B.prototype = new A;
  // B.prototype.constructor = B;
原文地址:https://www.cnblogs.com/2han/p/6362175.html