I am new to require.js and I need little guidance here.
/*
* This app depends on jquery and a remote script called "remote.js" (serve over localhost :p)
* Locally I will have main.js and require.js.
* main.js contain an entry function "init" and it depends on jquery
* and remote.js to be fully loaded.
*/
require.config({
paths: {
"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min",
"remote": "http://localhost:8000/scripts/remote"
},
shim: {
"init": {
deps: ["jquery", "remote"]
}
},
urlArgs: "bust=" + (new Date()).getTime()
});
define(["jquery", "remote"], function($, remote) {
console.log("just entered the outerscope of the init function.");
console.log(remote);
return {
init: function() {
console.log("entered init function");
}
}
});
/* the following is in remote.js*/
function remoteF1() {
console.log("remote function 1 is called.");
};
function remoteF2() {
console.log("remote function 2 is called.");
};
// and I thought about wrapping them around with "define" or "require"
I probably could define init.js, but say I want to keep that idea behind, how do I define a function called
init
inside this main.js file and use it as my entry-point which calls functions inremote.js
??Also, do I have to repeat
define/require(['jquery', 'remote'].....
the dependency array again when I define my function? Thanks