-3
我试图让我的头围绕错误的JavaScript承诺,因为我从来没有使用过。 现在,我已经看了一些教程,并在this one我决定尝试的代码,但是当我运行此:在命令node promise.js
Windows控制台窗口:与承诺
if (window.Promise) { // Check if the browser supports Promises
var promise = new Promise(function(resolve, reject) {
//asynchronous code goes here
});
}
我可以看到这个错误:
C:\Users\antobbo\Desktop\pdfSearch\promise.js:1
(function (exports, require, module, __filename, __dirname) { if (window.Promise) { // Check if the browser supports Promises
^
ReferenceError: window is not defined
at Object.<anonymous> (C:\Users\antobbo\Desktop\pdfSearch\promise.js:1:67)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
C:\Users\antobbo\Desktop\pdfSearch>
难道我做错了什么? 谢谢
您有评论'检查浏览器是否支持Promises',但你不运行这个脚本在浏览器中,这是'窗口'将被定义的地方。 – Gavin
有没有窗口,在命令行... – baao
卫生署!当然!对错误抱歉... – antobbo