-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfengzhuang.html
50 lines (47 loc) · 1.19 KB
/
fengzhuang.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
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="button" id='btn' value="点击我">
<script>
/* -- 封装 -- */
// 示例:
// http://www.cnblogs.com/Darren_code/archive/2011/08/31/JavascripDesignPatterns.html
var _packaging =function(){
//私有属性和方法
var name ='Darren';
var method1 =function(){
//...
};
//特权属性和方法
this.title ='JavaScript Design Patterns' ;
this.getName =function(){
return name;
};
};
//共有静态属性和方法
_packaging._name ='Darren code';
_packaging.alertName =function(){
alert(_packaging._name);
};
//共有属性和方法
_packaging.prototype = {
init:function(){
//...
}
};
// ------------------------实现-----------------------------------
console.log(_packaging);
// 调用静态属性和方法
alert(_packaging._name);
_packaging.alertName();
// 实例化对象
var package = new _packaging();
console.log(package);
//
</script>
</body>
</html>