還記得jQuery如何使用的么?Sea.js也是如此。例子在這里可以找到,用anywhere起個(gè)靜態(tài)服務(wù)來(lái)看看。
// File:js/module/greet.js
define(function (require, exports) {
function helloPython() {
document.write("Hello,Python");
}
function helloJavaScript() {
document.write("Hello,JavaScript");
}
exports.helloPython = helloPython;
exports.helloJavaScript = helloJavaScript;
});
如果你對(duì)Node.js非常熟悉,你可以把這個(gè)模塊理解為Node.js的模塊加上一個(gè)Wrapper。
<!-- File:index.html -->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting start with Sea.js</title>
<!-- 引入seajs-->
<script src="https://atts.w3cschool.cn/attachments/image/cimg/sea.js"></script>
</head>
<body>
</body>
</html>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting start width Sea.js</title>
<!-- 引入seajs-->
<script src="https://atts.w3cschool.cn/attachments/image/cimg/script>
<script>
seajs.use(['/js/module/greet'], function (Greet) {
Greet.helloJavaScript()
})
</script>
</head>
<body>
</body>
</html>
看到頁(yè)面上輸出的Hello,JavaScript
么,這確實(shí)太簡(jiǎn)單了!
更多建議: