-
Notifications
You must be signed in to change notification settings - Fork 0
/
chap1.js
155 lines (122 loc) · 2.85 KB
/
chap1.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Created by Administrator on 2017/8/24 0024.
*/
//灵活的语言
/*
最基本的写法
*/
function checkName(){
//........
}
function checkEmail(){
//.........
}
function checkPassword(){
//.........
}
//用对象收编变量
var CheckObject = {
checkName : function(){},
checkEmail : function(){},
checkPassword: function(){}
}
//对象的另一种形式
var CheckObject = function(){}
CheckObject.checkName=function(){};
CheckObject.checkEmail=function(){};
CheckObject.checkPassword=function(){};
//真假对象
var CheckObject = function(){
return {
checkName : function(){
//.......
},
checkEmail : function(){
//.......
},
checkPassword : function(){
//.......
}
}
}
var a = CheckObject();
a.checkEmail()
//类也可以
var CheckObject = function(){
this.checkName = function(){
console.log("This is a name")
};
this.checkEmail = function(){
console.log("This is a email")
};
this.checkPassword = function(){
console.log("This is a password")
}
}
var a = new CheckObject();
a.checkEmail();
a.checkName();
a.checkPassword();
//一个检测类
var CheckObject = function(){};
/*CheckObject.prototype.checkEmail = function(){}
CheckObject.prototype.checkName = function(){}
CheckObject.prototype.checkPassword = function(){}*/
CheckObject.prototype = {
checkEmail : function(){},
checkName : function(){},
checkPassword : function(){}
}
var Obj = {
checkName : function(){
console.log("This is checking name")
return this;
},
checkEmail : function(){
console.log("This is checking Email");
return this;
},
checkPassword : function(){
console.log("This is checking password");
return this;
}
}
Obj.checkName().checkEmail().checkPassword()
//函数的祖先;
/*Function.prototype.checkEmail = function(){
console.log("aaaaaaaa")
}
var f = function(){};
f.checkEmail()*/
/*
Function.prototype.addMethod = function(name,fn){
this[name] = fn;
}
var methods = function(){}
methods.addMethod("checkName",function(){
console.log("This is checking name")
})
methods.addMethod("checkEmail",function(){
console.log("This is checking email")
})
methods.addMethod("checkPassword",function(){
console.log("This is checking password")
})
console.log("-------------------------------")
methods.checkEmail()
methods.checkName()
methods.checkPassword()
*/
Function.prototype.addMethod = function(name,fn){
this.prototype[name] = fn;
return this;
}
var Methods = function(){};
Methods.addMethod('checkName',function(){
console.log("This is a name")
}).addMethod('checkEmail',function(){
console.log("This is a email")
return this;
})
var m = new Methods();
m.checkEmail().checkName();