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

    参考链接

  • 相关阅读:
    RF04 Variables
    RF06 Settings
    RF05 Keywords
    Nginx介绍
    javascript中的迷惑点
    javascript中的undefined和null
    常见博客网站的robots.txt
    CSS层叠样式表
    web前端校验
    了解javascript
  • 原文地址:https://www.cnblogs.com/justSmile2/p/9960024.html
Copyright © 2011-2022 走看看