'use strict';var a = 20;function foo () { var a = 1; var obj = { a: 10, c: this.a + 20, fn: function () { return this.a; } } return obj.c;}console.log(foo()); // ?console.log(window.foo()); // ?是不是因?yàn)檎{(diào)用foo函數(shù)的時(shí)候,返回obj.c。而obj.c是this.a+20.此時(shí)的this是指向undefined,(因?yàn)樵趪?yán)格模式下)所以沒有結(jié)果嗎?如果沒有用嚴(yán)格模式的話,這個(gè)this是指向window嗎?怎么指向window有點(diǎn)模糊?請各位指教.Uncaught TypeError: Cannot read property 'a' of undefined at foo (test.html:18) at test.html:26
調(diào)用foo函數(shù),返回obj.c。那么為什么會(huì)沒有結(jié)果類?
料青山看我應(yīng)如是
2019-02-15 10:15:38