-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearnfunc.html
More file actions
96 lines (81 loc) · 2.78 KB
/
learnfunc.html
File metadata and controls
96 lines (81 loc) · 2.78 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
arguments(伪数组): 所有函数内置的 存储了所有传递的实参
function fn(){
console.log(arguments);
}
fn(1, 2, 3)
伪数组
1. 具有数组的length属性
2. 索引方式存储
3. 没有真正数组的方法 pop()
//构造函数
function hero(name,type,blood,attack){
this.name = name;
this.type = type;
this.blood = blood;
this.attack = attack;
}
var hero1 = new hero('lianpo','力量型','500血量','近战');
var hero2 = new hero('houyi','射手型','100血量','远程');
console.log(hero1);
// new在执行时会做四件事情:
// 1.在内存中创建一个新的空对象。
// 2.让this指向这个新的对象。
// 3.执行构造函数里面的代码,给这个新对象添加属性和方法。
// 4.返回这个新对象(所以构造函数里面不需要return ) .
//遍历对象
var obj = {
name :'z',
sex :'女',
fn:function(){}
}
for(var k in obj){
console.log(k); //遍历属性名
console.log(obj[k]); //遍历属性值
}
//反转任意数组
function reverse(arr){
var newarr = [];
for(var i = arr.length - 1 ; i>=0 ; i--){
newarr[newarr.length] = arr[i];
}
return newarr;
}
var a = reverse([6,2,55,1]);
console.log(a);
//利用对象封装数学对象,含有PI 最大值和最小值
var math = {
PI: 3.1415926,
max : function(){
var max = arguments[0];
for(var i = 0;i < arguments.length;i++){
if(max < arguments[i])
max = arguments[i];
}
return max;
},
min: function(){
var min = arguments[0];
for(var i = 0;i < arguments.length;i++){
if(min > arguments[i])
min = arguments[i];
}
return min;
}
}
console.log(math.PI);
console.log(math.max(1 ,66 ,3));
math.max() //-Infinity
math.max(1,99,'1') //NaN
</script>
</head>
<body>
</body>
</html>