[英]Can't access Imported Node Module from within Node stdin
为什么我不能访问这个?
someFile.js
const Context = require('./Context');
const play = function(){
process.openStdin().on('data', function(res) {
if(Context.move(res, X)){ // I get an error here saying Context is undefined
... rest of the code
}
}
我不想不必修改行为,而是尽可能地修改代码。
如果您处于任何现代节点中,请使用箭头函数保留上下文:
const Context = require('./Context');
const play = () => {
process.openStdin().on('data', res => {
if(Context.move(res, X)){
... rest of the code
}
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.