【发布时间】:2018-06-19 12:58:35
【问题描述】:
我有以下代码:
module.exports = function(db, threads) {
var self = this;
this.tick = function() {
//process.chdir("AA/BB"); // This line gives error "Error: ENOENT: no such file or directory, uv_chdir"
}
this.start = function() {
process.chdir("AA/BB"); // this works
console.log("The new working directory is " + process.cwd());
self.tick(process);
}
}
我像这样从另一个类调用 start():
var man = require('./temp.js');
var manager = new man(db, threads);
manager.start();
谁能解释为什么我可以从 start() 更改目录,但不能从 tick() 更改目录?我需要在这些函数之间传递一些东西吗?
谢谢。
【问题讨论】:
-
在线 - self.tick(process);您正在传递一个变量进程,但“this.tick = function() { ”没有任何参数。
-
我尝试向函数添加参数并使用它们,但没有帮助:(这是要走的路吗?将进程传递给函数并以某种方式使用它?
标签: javascript node.js chdir