zoukankan      html  css  js  c++  java
  • 面试题-----闭包2

    1.

    var age=100;
    function test(){
    this.age=50;
    return function(){
    return this.age;
    }
    }
    var m=new test();//new出来的test实例对象,添加age属性并且赋值为50,m接收return返回的function(){return this.age};,匿名函数return回去的this.age,匿名函数没有age属性,所以结果为undefined

    //可以理解为此时的m其实是等于function(){return this.age};
    console.log(m.age);//undefined

  • 相关阅读:
    模板
    洛谷
    Codeforces
    Codeforces
    Codeforces
    Codeforces
    洛谷
    洛谷
    洛谷
    NOIP 普及组 2016 海港
  • 原文地址:https://www.cnblogs.com/luxiaoxiao/p/6066944.html
Copyright © 2011-2022 走看看