RequireJS にモジュールがあります。
define(['jquery', 'jsonLoader'], function($, jsonLoader){
function buildMenu() { jsonLoader('system/models/build/menu.json', function(data){ var output=''; // ... return output; }); } return { buildMenu : buildMenu } })
関数実行後buildMenu()
は「undefined」を返します(で定義したコールバックが実行されjsonLoader()
ないため)。ここで関数を呼び出しています:
define(["jquery", "core", "template", "jsonLoader", "debugger"], function($, core, template, jsonLoader) {
var config, debug; $(function() { jsonLoader('system/config.json',function(data){ config = data; init(); }); }); function init() { debug = new $.fn.debug; if(config.application.debug == true) debug.enabled = true // Build menu debug.log("Building Menu..."); console.log ( template.buildMenu() ); } });
jsonLoader は次のようになります。
define(["jquery"],function($){
return function(name, callback){ $.get(name, function(data){ callback(data); }); };
});
どこが間違っていますか?