属性和方法在不在的问题简单,可是属性和方法变不变化的问题可就严重了。在不在我们可以检测,变不变呢?比如,请看下面的代码:
转自此
http://blog.csdn.net/xiaoyuemian/archive/2009/01/20/3844305.aspx
- function MyObject(name, size)
- {
- this.name = name;
- this.size = size;
- }
-
- MyObject.prototype.color = "red";
- MyObject.prototype.tellColor = function()
- {
- return "color of "+this.name+" is "+this.color;
- }
-
- var myobj1 = new MyObject("tiddles", "7.5 meters");
- domDiv.innerHTML += myobj1.tellColor()+"<br /><br />";
-
-
-
- MyObject.prototype.color = "green";
-
-
-
- domDiv.innerHTML += myobj1.tellColor()+"<br /><br />";