当前位置: 代码迷 >> JavaScript >> Javascript prototype的例证
  详细解决方案

Javascript prototype的例证

热度:99   发布时间:2012-09-10 11:02:32.0
Javascript prototype的例子
<script>


function subClass(){ }
subClass.prototype =
{
    Name: "这个是原始值"
}

function myClass()
{
    //构造函数
}
 
myClass.prototype =
{
    ID: 1,
    Name: "johnson",
    SubObj: new subClass(),
    showMessage: function()
    {
        alert("ID: " + this.ID + ", Name: " + this.Name + "SubObj.Name:" + this.SubObj.Name);
    }
}

var obj0 = new myClass();
obj0.showMessage();
var obj1 = new myClass();
obj1.SubObj.Name = "After 修改过的";
obj1.showMessage();
var obj2 = new myClass();
obj2.showMessage();

</script>

  相关解决方案