<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
/**
匿名函数
效果:一开始创建的person1对象初始化后name后,
可以给name变量重新赋值;最后新建并初始化
person2的name时,person1的name也发生了变化,
证明name属性为静态变量。
*/
(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>
</HEAD>
<BODY>
</BODY>
</HTML>