zoukankan      html  css  js  c++  java
  • instanceof

            // instanceof  内部实现原理 
            console.log(instance_of(Function, Function));
            function instance_of(L, R) { 
                var O = R.prototype;
                L = L.__proto__; 
                while (true) {
                    if (L === null)
                        return false;
                    if (O === L) 
                        return true;
                    L = L.__proto__;
                }
            }
            
            Function instanceof Function
            //right: Function.prototype   ( Function 函数 对应的匿名函数对象 )
            //left: Function.__proto__    ( Function 函数 对应的匿名函数对象 )
    
            Object instanceof Function;
            //right: Function.prototype   ( Function 函数 对应的匿名函数对象 )
            //left: Object.__proto__    ( Function 函数 对应的匿名函数对象 ) 
    
            Object instanceof Object
            //right: Object.prototype   ( Object 函数 对应的原型对象 )
            //left: Object.__proto__    ( Function 函数 对应的匿名函数对象 )    Object.__proto__ .__proto__  ( Object 函数 对应的原型对象 )
    
            Function instanceof Object;
            //right: Object.prototype   ( Object 函数 对应的原型对象 )
            //left: Function.__proto__    ( Function 函数 对应的匿名函数对象 )    Function.__proto__.__proto__    ( Object 函数 对应的原型对象 )
    Object 是函数
    函数也是对象,对象(除了null)都有 __proto__ 属性,指向其原型函数,通过 __proto__ 属性形成原型链。
    构造函数的 constructor 都指向 Function
    Function 的 prototype 指向一个特殊匿名函数,且这个特殊匿名函数的 __proto__ 指向 Object.prototype

    参考链接

  • 相关阅读:
    根据IP获取省市 .
    支付宝接口使用步骤及总结
    最新调用优酷视频 免前置广告的方法
    SQL新增数据取表主键最新值
    JS获取地址栏参数
    图片(img标签)的onerror事件
    prototype.js的Ajax对IE8兼容问题解决方案
    基于.net技术的 Rss 订阅开发
    JS获取Dropdownlist选中值
    阿里云tomcat启动慢
  • 原文地址:https://www.cnblogs.com/justSmile2/p/9960024.html
Copyright © 2011-2022 走看看