これはmain.jsに関するものですが、私はオンラインで見つかったすべての例を試してみましたが、うまく動作しませんでした。どのように定義された関数をRequireJSでhtmlで呼び出すのですか?
私は現在持っている:3つのモジュール(one.js、two.js、three.js)、main.js、index.htmlをとrequire.js
one.js
のようないくつかの参照ファイル:
define("one",['./two', './three'], function(two, three) {
var one = 1;
return {
value: function(e){
return one;
}
}
});
を
two.js
:
define("two",['./one', './three'], function(one, three) {
var two = 2;
return {
value: function(){
return two;
}
}
});
main.js
:
require(["one", "two", "three"], function (one, two, three) {
});
マイHTML:
<html>
<head>
<title>My App</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
// the function from two.js having the same name as another in one.js needs to be called here.
<body onload="value();">
<h1>My App</h1>
</body>
</html>