-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs调用方式.html
41 lines (41 loc) · 1.05 KB
/
js调用方式.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
// 方法调用模式
// 函数调用模式
// 构造器调用模式
// apply调用模式
/***************************方法调用模式*************************/
var myObject = {
value:1111,
inc:function(){
// 请注意this此时指向myobject
// console.log(this.value)
}
}
myObject.inc()
/***************************函数调用模式*************************/
var add = function(a,b){
// console.log(this) //请注意this此时指向window
return a+b
}
var sum = add(3,4)
/*******************************************************************/
function makeArray(arg1,arg2){
return [this,arg1,arg2]
}
console.log(makeArray('one','two')) //[Window, "one", "two"]
/*******************************************************************/
var arrayMake = {
value:1,
make:makeArray
}
console.log(arrayMake.make('one','two')) //[Object, "one", "two"] this指向arrayMake
</script>
</body>
</html>