1
此流星代碼嘗試調用send
函數,但服務器報告錯誤「send is not defined」,並且如果將罪魁禍首行更改爲request.send
,則得到Object沒有方法發送。從公共方法調用模塊的私有函數
爲什麼以及如何解決它?由於
request = (function() {
const paths = {logout: {method: 'GET'}}
const send =() => {some code}
return {
registerRequestAction: (path, func) => {
paths[path].action = func;
},
invoke: (type) => {
paths[type].action();
}
}
}());
request.registerRequestAction('logout',() => {
send(); // send is not defined
request.send(); // object has no method send
});
request.invoke('logout'); // to fire it up