摘要: var User = { count: 1, getCount: function() { return this.count; }};console.log(User.getCount());var func = User.getCount;console.log(func()); 这种情况下,正确的答案是1和undefined。你会很吃惊,因为有很多人被这种最基础的上下文问题绊倒。func是在winodw的上下文中被执行的,所以会访问不到count属性。我向侯选人解释了这点,然后问他们怎么样保证User总是能访问到func的上下文,即返回正即的值:1 正确的答案是使用Fun... 阅读全文
posted @ 2014-01-02 13:01 Kevin Liu Blog 阅读(234) 评论(0) 推荐(0)