Jak wywołać funkcję z innej funkcji w deklaracji module.exports?Węzeł JS wywołuje funkcję "lokalną" w module.exports
Mam projekt węzła struktury jv MVC i kontroler o nazwie TestController.js. Chcę uzyskać dostęp do metody w kontrolerze, ale przy użyciu this
kluczowe daje poniżej błędu:
cannot call method getName of undefined
"use strict"
module.exports = {
myName : function(req, res, next) {
// accessing method within controller
this.getName(data);
},
getName : function(data) {
// code
}
}
Jak uzyskać dostęp do metody z kontrolerem?
Wartość 'this' zależy od kontekstu wykonania, a nie jak funkcja jest zdefiniowana. – adeneo