a
被打印了,它存在函數(shù)之中(也就是聲明了),但是依然是 undefined
。換言之,上述代碼和以下代碼是相同的。function test() { var a; function foo() { return 2; } console.log(a); console.log(foo()); a = 1;}test();
問題4: this
在javascript中是如何工作的
以下代碼的結(jié)果是什么?請(qǐng)解釋你的答案。
var fullname = 'John Doe';var obj = { fullname: 'Colin Ihrig', prop: { fullname: 'Aurelio De Rosa', getFullname: function() { return this.fullname; } }};console.log(obj.prop.getFullname());var test = obj.prop.getFullname;console.log(test());