这是关于main.js我猜,但我已经尝试了我在网上找到的所有例子,他们只是没有工作。如何在HTML中通过RequireJS调用已定义的函数?
我目前:三个模块(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>