• js原型链笔记


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>

    可正常计算的范围 小数点前 16位, 后16位。


    构造函数特点 大驼峰命名法 new


    原型:
    1.定义(prototype):
    原型是function对象的一个属性,它定义了构造函数制造出的对象的
    公共祖先。通过该构造函数产生的对象,可以继承改原型的属性和方
    法。原型也是对象。
    2.利用原型特点和概念,可以提取公有属性。
    3.对象如何查看原型-->隐式属性 __proto__ 里面指向的是原型(原型链的连接点)
    4.对象如何查看对象的构造函数-->constructor (手动可以更改)

    <!--a.sayName() sayName里面的this指向是,谁调用的这个方法,this结束指向谁 -->
    绝大多数对象的最终都会继承自Object.prototype Object.create(null)这个不会继承自Object.prototype
    Object.create(原型,例如 Person.prototype)

    call/apply:
    作用:改变this指向。
    区别:后面传的参数形式不同。
    差距:传参列表不同
    call:需要吧实参按照形参的个数传进去
    apply:需要传一个arguments


    继承发展史:
    1.传承形式-->原型链
    过多的继承了没用的属性
    2.借用构造函数(call/apply)
    不能继承借用构造函数的原型
    每次构造函数都要多走一个函数
    3.共享原型 (函数.prototype = 函数.prototype)
    不能随便改动自己的原型
    4.圣杯模式



    <script type="text/javascript">


    // Person.prototype 原型
    // Person.prototype = {} 是 var person = new Person(); 的祖先

    Person.prototype = {
    proto : 123,
    };
    function Person(name , age , sax) {
    this.name = name;
    this.age = age;
    this.sax = sax;
    }
    var person = new Person('旺飞', 20 , 'male');

    // 借用构造函数
    function Person(name, age, sex) {
    this.name = name;
    this.age = age;
    this.sex = sex;
    }
    function Student(name, age, sex, tel, grade) {
    Person.call(this, name, age, sex);
    this.tel = tel;
    this.grade = grade;
    }
    var student = new Student('xie', 20, 'male', 111, 2019);



    // 继承
    // 1.圣杯模式
    Father.prototype.lastname = 'deng';
    function Father() {}
    function Son() {this.sex = 'hehe';}
    function inherit(Target, Origin) {
    function F() {}
    F.prototype = Origin.prototype;
    Target.prototype = new F();
    Target.prototype.constructor = Target;
    Target.prototype.uber = Origin.prototype; // 超类
    }
    inherit(Son, Father);
    var son = new Son();
    var father = new Father();

    //2. 圣杯模式TUI3 建议使用第二种

    Father.prototype.lastname = 'deng';
    function Father() {}
    function Son() {this.sex = 'hehe';}
    var inherit = (function () {
    var F = function () {};
    return function (Target, Origin) {
    F.prototype = Origin.prototype;
    Target.prototype = new F();
    Target.prototype.constructor = Target;
    Target.prototype.uber = Origin.prototype;
    }
    }());
    inherit(Son, Father);
    var son = new Son();
    var father = new Father();
    </script>


    </body>
    </html>
  • 相关阅读:
    App.config使用ASP.NET Web Project的Transformation模式编译方式
    简易扩展Visual Studio UnitTesting支持TestMethodCase
    Microsoft Unity ---- 系列文章
    Reflector 7.0.0.420 注册破解版
    在Vue前端界面中,几种数据表格的展示处理,以及表格编辑录入处理操作。
    基于Vue的工作流项目模块中,使用动态组件的方式统一呈现不同表单数据的处理方式
    在Vue前端项目中,附件展示的自定义组件开发
    在Vue&Element前端项目中,对于字典列表的显示处理
    kestrel对接elasticsearch踩坑记
    华为智慧安平解决方案——安防视频监控是核心
  • 原文地址:https://www.cnblogs.com/xiewangfei123/p/12251893.html
Copyright © 2020-2023  润新知