簡體   English   中英

對象[object Object]沒有方法'test'

[英]Object [object Object] has no method 'test'

我正在嘗試在另一個模塊中使用某個功能,但我無法使用它,也許我知道這是什么問題?

 this.test = function(callback) {
        callback('i am test');
    };
    module.exports.config = function (settings, callback) {
    this.test(function(err,res){
    console.log(res);
    });
    };

this ,因為你是另一個函數內部是不同的。 嘗試以下方法:

this.test = function(callback) {
  callback('i am test');
};
var self = this;
module.exports.config = function (settings, callback) {
  self.test(function(err,res){
    console.log(res);
  });
};

或者只是給出函數名稱並直接調用它:

function test(callback) {
  callback('i am test');
};
module.exports.config = function (settings, callback) {
  test(function(err,res){
    console.log(res);
  });
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM