我學習節點JS和我得到預期的對象,在1號線的Microsoft JScript運行時錯誤運行代碼時對象預計微軟的Jscript運行時錯誤 - 節點JS
var fs = require('fs');
function FileObject() {
this.filename = null;
this.exists = function(callback) {
var self = this;
fs.open(this.filename, 'r', function(err, handle){
if(err){
console.log(self.filename+ 'does Not exist');
callback(false);
}
else {
console.log(self.filename+ 'does Exist Indeed');
callback(true);
fs.close(handle);
}
});
};
}
var fo = new FileObject();
fo.filename = 'doesnotexist';
fo.exists(function(does_it_exist) {
console.log('results from exists:' + does_it_exist);
});
*您如何運行此腳本? – apsillers 2014-09-30 19:47:19
我試圖從命令提示符運行代碼 – SankarSV4791 2014-10-05 16:44:33
您能準確地顯示您是如何嘗試從命令行執行腳本的嗎? – mscdex 2014-10-05 17:29:30