【发布时间】:2015-03-23 12:00:15
【问题描述】:
为什么下面的代码会导致三次true?
第二步我排除了false。
function foo() {
this.bar = function () { };
};
console.log("foo - defined : " + typeof window.foo !== 'undefined');
console.log("bar - defined : " + typeof window.bar !== 'undefined');
foo();
console.log("bar - defined : " + typeof window.bar !== 'undefined');
【问题讨论】:
-
你应该是:
(typeof window.foo !== 'undefined')
标签: javascript function typeof