-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_dome.html
65 lines (63 loc) · 1.32 KB
/
module_dome.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
(function ($) {
//对$进行初始化
var $ = $||{};
//定义方法
$.define=function(str,fn) {
//将转换为数组
var strArr = str.split(".")
firstlvble = strArr[0];
if(strArr[0]==="define" || strArr[0] =="use" ){
strArr.splice(0, 1)
}
if(fn){
this[strArr[0]] =fn;
}
};
//使用方法
$.use =function() {
var agrs = [].slice.call(arguments)
var moduleNames =agrs[0]
if(!(moduleNames instanceof Array)){
return;
}
var fn =agrs[1];
var modelArry =[];
for (var i = 0; i < moduleNames.length; i++) {
var moduleName = moduleNames[i]
if (typeof moduleName ==="string") {
modelArry.push(this[moduleName])
} else {
modelArry.push(moduleName)
}
}
fn.apply(null,modelArry)
};
window.$ =$;
})(window.$);
</script>
<script type="text/javascript">
$.define("off",function() {
alert("message")
})
$.define("add",function(){
var sum =0;
for (var i = 0; i < arguments.length; i++) {
if(typeof arguments[i] ==="number")
sum += arguments[i];
}
return sum
})
$.use (["add",window],function (a,b) {
console.log(a(55,"4",555,"44"))
})
</script>
</head>
<body>
</body>
</html>