zoukankan      html  css  js  c++  java
  • __proto__指向问题

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

    </body>
    </html>
    <script type="text/javascript">

    // prototype和__proto__

    // prototype:
    // 每个函数都会有一个prototype这个属性,这个属性指向一个对象,这个对象就叫做原型对象;
    // function Fn(){} Fn.prototype={}


    // String Array Object Function Date RegExp 都有prototype
    // console.dir(Array)

    // 验证方法:typeof . . instanceof

    // 对象是通过函数创建的,而函数又是一种对象(所以有__proto__)

    // function Fn(){}

    // console.log(Fn instanceof Object)


    // __proto__:指向创建自己的那个构造函数的原型对象

    // constructor:指向创建自己的那个构造函数


    function Fn(){}

    var f1=new Fn();


    // console.log(f1.__proto__===Fn.prototype)

    // console.log(Fn.__proto__===Function.prototype)

    console.log(Function.__proto__===Function.prototype)

    // console.log(Function.prototype.__proto__===Object.prototype)


    var obj={}
    console.log(obj.__proto__.__proto__===null) //true
    console.log(obj.__proto__.constructor===Object) //true
    console.log(obj.__proto__.constructor.__proto__===Function.prototype) //true
    console.log(obj.__proto__.constructor.__proto__.__proto__===Object.prototype) //true
    console.log(obj.__proto__.constructor.__proto__.__proto__.__proto__===null) //true
    console.log(obj.__proto__.constructor.__proto__.__proto__.constructor.__proto__===Function.prototype)

    // 需要注意的指向是

    // 1. Function的__proto__指向其构造函数Function的prototype;

    // 2. Object作为一个构造函数(是一个函数对象!!函数对象!!),所以他的__proto__指向Function.prototype;

    // 3. 所有构造函数的的prototype方法的__proto__都指向Object.prototype(除了....Object.prototype自身);

    // 4. Object.prototype的__proto__指向null(尽头);




    </script>

  • 相关阅读:
    将十六进制的颜色字符串转为UIColor
    NSXMLParser读取XML文件并将数据显示到TableView上
    TouchJSON的简单使用
    NSJSONSerialization的简单用法
    Android 开发之修改 app 的字体大小(老人模式)
    android sqlite3:数据库操作
    设计模式-观察者模式(Observer Pattern)
    Android 7.0 介绍和适配问题
    Appium的安装和使用
    Android:使用 DownloadManager 进行版本更新,出现 No Activity found to handle Intent 及解决办法
  • 原文地址:https://www.cnblogs.com/xin1021/p/9216368.html
Copyright © 2011-2022 走看看