据MDN称:
Map.length
length属性的值为0.
这有什么用例?我理解为什么Map.size语义正确.但肯定的是Map.length,几乎总是返回"错误"的答案是一个坏主意,特别是如果有一个疏忽从ES5迁移代码.有没有办法在使用它时强制出错?
测试失败时有没有办法触发npm的posttest?如果package.json包含
"scripts": {
"pretest": "echo pretest",
"test": "some_failed_test_or_error",
"posttest": "echo posttest"
}
Run Code Online (Sandbox Code Playgroud)
$ npm test 将回应"预测试"但不是"后测".
如果我使用mocha并且测试失败,我会得到相同的行为,即使mocha没有触发任何异常(只是一些简单的失败assert(true==false)).
我正在启动预测试资源,我想在posttest上杀死资源,无论测试本身是通过还是失败.
MacOS OS X 10.9.4,npm版本1.4.21,节点v0.10.30.
如何捕获调用不存在的文件的.fork()错误?
var cp = require('child_process');
var fk = cp.fork("missing-file.js");
Run Code Online (Sandbox Code Playgroud)
喷涌而出
module.js:340
throw err;
^
Error: Cannot find module 'path-to-here/missing-file.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Run Code Online (Sandbox Code Playgroud)
我试过了
try {
var cp = require('child_process');
var fk = cp.fork("missing-file.js");
} catch(err) {
console.log("async error doesn't get caught here.");
}
fk.on('error', function(err) {
console.log("this never gets called");
})
process.on('uncaughtException', function(err) {
console.log("this never gets called either");
});
Run Code Online (Sandbox Code Playgroud)
但是这些都没有发现错误。
Joyent的文档说,在以下情况下应发出错误事件:
但这似乎发生在#1之前。
与此类似的问题.我有非自定义安装,我想知道数据实际存储在哪里.它不是在/var/lib/elasticsearch/nodes/0/indices/{nameOfYourIndex}/(0-4}/index链接问题的已接受答案中指出的.
我可以从脚本中使用节点4.2.6中的查询字符串,但我可以从节点提示符.这是一些证据.
我有以下脚本:
$ cat test.js
console.log(process.versions)
console.log(querystring)
Run Code Online (Sandbox Code Playgroud)
我运行时遇到错误:
$ node test.js
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '46',
openssl: '1.0.2e' }
/path/to/file/test.js:2
console.log(querystring)
^
ReferenceError: querystring is not defined
at Object.<anonymous> (/path/to/file/test.js:2:13)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
Run Code Online (Sandbox Code Playgroud)
但是如果我在命令行进入节点,我就不会收到错误.
$ node
> console.log(process.versions)
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV', …Run Code Online (Sandbox Code Playgroud)