Senior JS (c)

Inherited property

  • Method call: this refers to the parent of this subclass

Inherited methods

  • Method: save the object instance of the parent class to the prototype object subclass

  • Instance of an object class is assigned to the parent subclass prototype object, and then back to the constructor means

  • 一般情况下,对象的方法都在构造函数的原型对象中设置,通过构造函数无法继承父类方法。核心原理:
    
    ①将子类所共享的方法提取出来,让子类的prototype 原型对象= new 父类()  
    
    ②本质:子类原型对象等于是实例化父类,因为父类实例化之后另外开辟空间,就不会影响原来父类原型对象
    
    ③将子类的constructor指回子类的构造函数
    function Father() {
    }
    Father.prototype.sing = function () {
      console.log('唱');
    };
    function Son() {
    }
    // 这个赋值的是地址,公用一个空间,改一个就全改
    // Son.prototype = Father.prototype;
    
    // 父类的实例对象赋值给子类的原型对象,然后指回构造函数
    // 单独new一个空间给Son用{
    Son.prototype = new Father();
    Son.prototype.constructor = Son;
    Son.prototype.dance = function () {
      console.log('tiao');
    };
    var obj = new Son();
    obj.sing();
    obj.dance();
    console.log(Son.prototype);
    console.log(Father.prototype);
    • Property inheritance, method inheritance

      • Properties: call: this refers to the parent of this subclass

      • Method: instance of an object class is assigned to the parent subclass prototype object,

      • constructor prototype object of a subclass constructor must refer back to the subclass

        实现继承后,让Son指回原构造函数
        
        Son.prototype = new Father();
        
        Son.prototype.constructor = Son;
  • Constructor implemented using attribute inheritance, implementation with the prototype object inheritance

The nature of the class

  • class nature or function

ES5 new method

Iterate

  • forEach (function (element, index, [itself iterated array]) {})
  • filter () can make screening
    • array.filter(function(){})
    • Mainly used for screening
    • Returns a new array
  • some()
    • Find, find the need to find value exists
    • Returns a Boolean value
    • return element === 100;
    • Found stop traversal
  • Traverse the object
    • obj【key】

Guess you like

Origin www.cnblogs.com/itxcr/p/11600081.html