這是關於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>