【发布时间】:2015-11-24 12:58:15
【问题描述】:
我是 qUnit 测试的新手,很难理解为什么我的变量“a”通过了范围测试,即使在定义“a”之前调用了测试。当我注销“a”时,它的行为符合预期。谁能给个提示?
代码如下:
function outer() {
test('inside outer', function (assert) {
assert.equal(typeof inner, "function", "inner is in scope"); //pass
assert.equal(typeof a, "number", "a is in scope"); // pass
});
console.log(a); // undefined
var a = 1;
console.log(a); // 1
function inner() {}
var b = 2;
if (a == 1) {
var c = 3;
}
}
outer();
【问题讨论】:
标签: javascript scope qunit