-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path07.encapsulation.html
59 lines (50 loc) · 1011 Bytes
/
07.encapsulation.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
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// function Person (name) {
// var age = 30
// this.name = name
// function pm () {
// console.log('private method')
// }
// this.test = function () {
// console.log('public method')
// }
// }
// var p = new Person('xxx')
// p.pm() //Uncaught TypeError: p.pm is not a function
// p.test() //public method
// function Person (name) {
// this.name = name
// function pm () {
// console.log(this.name)
// }
// this.test = function () {
// console.log('public method')
// // pm()
// pm.call(this)
// }
// }
// var p = new Person('AA')
// p.test() //AA
// function person (pname) {
// function pm () {
// console.log(self.name)
// }
// var self = {
// name: pname,
// test: function () {
// pm()
// }
// }
// return self
// }
// var p = person('bb')
// p.test() //bb
</script>
</body>
</html>