【发布时间】:2016-08-04 07:42:31
【问题描述】:
我正在尝试从同一文件中的另一个函数调用一个函数作为回调。
下面的代码没有显示错误,但什么也没做 - 有没有不同/更好的方法来做到这一点?
我正在从 require 配置文件 (require-main.js) 调用第一个函数,效果很好
define(['require-main'], function() {
require(['getJSON'], function(getJSON) {
getJSON.stations();
});
});
getJSON.js
define(['jquery', 'domChange', 'setUp'], function($, domChange, setUp) {
var self = this;
return {
stations: function() {
$.get('/js/ajax/stations.json', function(sol) { /* local JSON */
tmv.stations = sol;
console.log(sol); /* this is fine */
self.lines; /* <-- call next function */
});
},
lines: function() {
console.log('foo'); /* NOT called */
$.get('/js/ajax/lines.json', function(lines) { /* local JSON */
/* do something */
});
}
}
});
I've seen this question but I can't work this way as the order is not predetermined
更新:如上所述,尝试将this 缓存到 var 中,但仍然没有乐趣
【问题讨论】:
-
this.lines这是函数的引用,你实际上并没有调用它
标签: javascript requirejs