<code><script type="text/javascript"> function Person(){} Person.prototype.array = new Array("Koji", "Luo"); Person.prototype.showArray = function(){ alert(this.array); } var obj1 = new Person(); //生成一个Person对象 var obj2 = new Person(); obj1.array.push("Kyo"); //向obj1的array属性添加一个元素 obj1.showArray(); //Koji,Luo,Kyo obj2.showArray(); //Koji,Luo,Kyo </script> </code>
If an element is added to the array of obj1, it will also be added to the array of obj2.
Is the array they inherit a pointer? Everyone has the array in the prototype object?
<code>//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?) </code>
Thank you everyone..