zoukankan      html  css  js  c++  java
  • 面试题1

    1、

    var ryl = {
        bar: function(){
            return this.baz;
        },
        baz: 1
    };
    
    (function(){
        console.log(typeof arguments[0]()); //undefined
    })(ryl.bar);

     2、

    function test(){
        console.log("out");
    }
    
    (function(){
        if(false){
            function test(){  
                console.log("in");
            }
        }
        test();
    })();
    
    // 等价于
    function test(){
        console.log("out");
    }
    
    (function(){
           var test; // 变量提升
        if(false){
            function test(){  
                console.log("in");
            }
        }
        test();
    })();
    
        

     3、

      function yideng() {
            return
            {
              a:1
            }
          }
          var result = yideng()
          console.log(result.a) // 报错,因为return 换行
    

    4、

    var yideng = {
            n: 1
          }
          yideng.x = yideng = {
            n: 2
          }
          console.log(yideng.x) // undefined
    
    

    yideng.x = yideng = { n: 2 }; 这里非常特殊

    
    

    “.“运算符的优先级要高于”=“的优先级,所以这里的次序是

    
    

    1.创建了一个x属性,值为undefined,挂在yideng下。

    
    

    2.yideng的指向被改变,指向了{n:2}

    
    

    3.刚才创建的x属性被赋值为{n:2}

    
    

    4.由于yideng的指向已经改变,不再指向原有的对象,所以yideng.x就为undefined

     
  • 相关阅读:
    socket套接字通信和粘包问题
    TCP协议
    网络编程
    单例模式
    类的内置方法(魔法方法)
    反射(hasattr和getattr和setattr和delattr)
    isinstance与issubclass
    绑定方法与非绑定方法
    鸭子类型
    类的多态和抽象类
  • 原文地址:https://www.cnblogs.com/ron123/p/9339074.html
Copyright © 2011-2022 走看看