-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24-call和apply应用.js
More file actions
59 lines (47 loc) · 1.14 KB
/
Copy path24-call和apply应用.js
File metadata and controls
59 lines (47 loc) · 1.14 KB
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
function func() {
let args1 = Array.from(arguments)
console.log(args1);
console.log('--------------------');
let args2 = [...arguments]
console.log(args2);
console.log('--------------------');
let args3 = []
for (let i = 0; i < arguments.length; i++) {
args3.push(arguments[i]);
}
console.log(args3);
console.log('--------------------');
/**
* Array.prototype.slice
*/
let arr = [10, 20, 30, 40]
console.log(arr.slice());
let args4 = Array.prototype.slice.call(arguments)
console.log(args4);
console.log('--------------------');
console.log('--------------------');
}
func(10, 20, 30, 40)
console.log('--------------------');
console.log('--------------------');
function func1() {
Array.prototype.forEach.call(arguments, (item) => {
console.log(item);
})
}
func1(10, 20, 30, 40)
console.log('--------------------');
console.log('--------------------');
let arr = [12, 3, 25, 45, 1, 12]
// 1
let max = arr.sort((a, b) => b - a)[0]
console.log(max);
// 2
max = arr[0]
arr.slice().forEach(item => {
max > item ? max : max = item
})
console.log(max);
// 3
max = Math.max.apply(Math, arr)
console.log(max);