I'm using NodeJs to run this code this is my custom module
call = {}; call.hangup = { searching: function(number, mysql, validator){ this.number = number; this.mysql = mysql; this.validator = validator; var query = "{sql...}"; try { mysql.query(query, function(err, rows, fields) { if (err) throw err; if(!validator.isNull(rows)) { return rows.leadid; }else { return false; } }); }catch(error) { console.log(error); } }, test: function(number, mysql, validator){ var self = this; this.number = number; this.mysql = mysql; this.validator = validator; var result = self.searching(number, mysql, validator); console.log(result); } }; module.exports = call; then call test function in my main file
call.hangup.test(number, connection, validator); but I'm getting this error code in my console :
var result = self.searching(leadid, mysql, validator); ^ TypeError: undefined is not a function how can I fix it ? and why this happen ?
Console.logthisinside it to see if the context is what you expect. You can alsobindit, or usecalletc to set it but you should find whats changing it. Also why are you aliasingthiswithself? There's no need. Also you settingnumbermysqlandvalidatortwice. You should either pass it intosearchingfor it to set or set it intestand just read them insearching.testin such a way thatthisdoes not point to the correct object, it could be that your error is from a different section of code.