-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (46 loc) · 1.18 KB
/
script.js
File metadata and controls
65 lines (46 loc) · 1.18 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
/*** Object对象 ***/
// 创建对象 - 方法1
var ztaer = {
year: 18,
name: 'oo7',
skills: [ 'h5/css3','js','python3','linux' ],
gf: false
};
var oo7 = new Object(); // 创建对象 - 方法 2
// 索引对象属性
console.log( ztaer.year );
console.log( ztaer[ 'name' ] );
console.log( ztaer.skills[1] );
// 修改对象属性
ztaer.year = 20;
ztaer['name'] = '__OO7__';
console.log( ztaer );
// 添加属性给对象
oo7.name = 'ztaer';
oo7['sex'] = 'man';
console.log( oo7 );
/***** 函数 *****/
// 函数的创建 - 第一种
function test( x ){
return x;
}
// 函数的创建 - 第二种
test2 = function( y ){
return y;
}
console.log( test(2) + ' ' + test2(3) );
/***** object关于this使用,以及对象中函数创建 *****/
// object的函数创建其实依据第二种函数创建方法
// this使用:
// a) this.变量,可以调用自身对象属性
// b) this.变量。 也可以创建自身属性
var boy = {
birthYear: 1998,
calcAge: function( year ){ // 创建函数
// this 可以调用自身已有属性,也可以创建新属性
this.age = year - this.birthYear;
return this.age;
}
}
// 对象函数调用
console.log( boy.calcAge( 2019 ) );