-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPrivilegedMethodExample02.htm
38 lines (29 loc) · 1.09 KB
/
PrivilegedMethodExample02.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Privileged Method Example 2</title>
</head>
<body>
<script type="text/javascript">
(function(){
var name = "";
Person = function(value){
name = value;
};
Person.prototype.getName = function(){
return name;
};
Person.prototype.setName = function (value){
name = value;
};
})();
var person1 = new Person("Nicholas");
alert(person1.getName()); //"Nicholas"
person1.setName("Greg");
alert(person1.getName()); //"Greg"
var person2 = new Person("Michael");
alert(person1.getName()); //"Michael"
alert(person2.getName()); //"Michael"
</script>
</body>
</html>