-1
コンストラクタのスコープを保持する方法やこれまでどんな呼び出しをしたいのか分かりません。単にグローバル変数に置き換えられます。モジュールのコンストラクタとasyncの使用
私は複数の関数を呼び出し、それぞれ異なるデータを生成し、異なる変数を設定します。
どうすればこの問題を解決できますか?
function Foo(user, data) {
this.user = user;
this.data = data;
}
Foo.prototype.init = function(callback) {
async.series([
this.functionOne,
], function(err, result) {
callback(err, []);
});
};
Foo.prototype.functionOne = function(callback) {
console.log(this);
this.username = "abc";
callback(null);
}
module.exports = Foo;
あなたはおそらく、あなたが
.bind()
を使用して、メソッド参照を渡すとき
this
値を保持する必要がある