Tag: 范围

variables作用域如何在Mochatesting框架内工作?

我是一个JavaScript,node.js,摩卡等所有东西的相对新手。 在我的代码中,我有一个单元对象有一个disable() ,设置禁用属性为true和isDisabled() ,返回禁用的属性。 它也有一个方法nextTurnReset() ,在下一回合开始时重置单位。 我写了一个testing套件来testing这种行为。 我首先禁用对象,然后尝试testing以查看它是否被禁用。 但是,我的第一个testing中的单元variables(在传递给Mocha的it()方法的匿名函数中it()处于非禁用状态,正如我在节点的debugging器中观察到的那样。 describe('#disable()', function() { var unit = tests.newUnit(); unit.disable(); debugger; it('disabled off turn?', function() { debugger; (unit.isDisabled()).should.be.exactly(true); }); unit.nextTurnReset(); it('disabled on next turn?', function() { (unit.isDisabled()).should.be.exactly(true); }); unit.nextTurnReset(); it('disabled on 2nd turn?', function() { (unit.isDisabled()).should.be.exactly(false); }); }); 为logging,前两个testing失败,最后一个成功,表明该单位从来没有被禁用。 从使用节点debugging器的repl:在第一个debugger; 声明, unit.disabled == true ,但在第二个debugger; 语句unit.disabled == false […]

调用循环内的asynchronous函数

var path; for (var i = 0, c = paths.length; i < c; i++) { path = paths[i]; fs.lstat(path, function (error, stat) { console.log(path); // this outputs always the last element }); } 如何访问传递给fs.lstat函数的pathvariables?

meteor中的全局variables

我有 var Schemas = {}; Meteor.isClient && Template.registerHelper("Schemas", Schemas); Schemas.Person = new SimpleSchema({ fullName: { type: String, index: 1, optional: true, }, email: { type: String, optional: true }, address: { type: String, optional: true }, isActive: { type: Boolean, }, age: { type: Number, optional: true } }); 在一个文件中 var Collections = {}; Meteor.isClient […]