zoukankan      html  css  js  c++  java
  • call apply 原型 原型链

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
        function A(name){
            this.name=name;
        }
        function B(age){
            this.age=age;
        }
        function C(sex,name,age){
            this.sex=sex;
           A.call(this,name);//apply(this,[name])
           B.call(this,age)
        }  
        var c=new C('male','wnag',17); 
         </script>
    </body>
    </html>
    //call需要把实参按照形参的个数传递进去
    //apply需要传一个arguments的
    //改变this指向 ,传参不同

     原型

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
        //Person.prototype---原型
        //Person.prototype={}---祖先
        Person.prototype.name="like"; //公有祖先
        Person.prototype.say=function (){
            console.log('love');
        }  
        function Person(age,sex){
          this.age=age;
          this.sex=sex;
        }
        var person= new  Person(18,'male');
        var person1=new Person(40,'femal');    
           </script>
    </body>
    </html>
    //1.函数对象有_proto_和prototype属性
     2.非函数对象只有_proto_属性
     3.prototype中有_proto_属性,是Object构造出来的
     4.函数对象_proto_指向它的创建者及Function构造函数
     5.Function构造函数_proto_指向它自己
     6.Object对象的prototype中的_proto_是null

    原型链

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
        Grand.prototype.name='wang';
        function Grand(){
    
        }
        var grand=new Grand();
        Father.prototype=grand;
        function Father(){
            this.name='xu';
        }
        var father=new Father();
        Person.prototype=father;
        function Person(){
            this.hobbit='woshiwudi';
        }
        var person =new Person();
        </script>
    </body>
    </html>
    
    var son={
        name:'lang';
    }
    var person=Object.create(son);
    Object.create(null)没有原型
  • 相关阅读:
    H5定位终极解决方案
    软帝学院教你使用cookie法,查看最近看过的书
    你真的会用Gson吗?Gson使用指南(一)
    Java程序员应当知道的10个面向对象设计原则
    java获取当前月第一天和最后一天,上个月第一天和最后一天
    正则基础教程一些冷门的知识
    爆笑的程序员梗,笑死人不偿命!
    java字符串操作扩充:灵活截取字符串
    如何分析及处理 Flink 反压?
    与君初相识,犹如故人归
  • 原文地址:https://www.cnblogs.com/wxy0715/p/12442280.html
Copyright © 2011-2022 走看看