日期:2014-05-16 浏览次数:20359 次
function Bird(){ } var bird = new Bird(); alert(Bird.prototype); // [object Object] alert(bird.prototype); // undefined
function Animal(){ this.color = "red"; } function Bird(){ this.name="小鸟"; } var b = new Bird(); alert(b.color); // undefined Bird.prototype = new Animal(); var b_ = new Bird(); alert(b_.color); // red
Array.prototype.pushEx = function(obj){ var a = true; for (var i = 0; i < this.length; i++) { if (this[i]== obj) { this[i] = obj; a =false; break; } } if(a){ this.push(obj); } return this.length; } var test1 = new Array(); test1.pushEx("bb"); test1.pushEx("bb"); test1.pushEx("dd"); alert(test1) //bb,dd