摘要: js继承有5种实现方式:1、继承第一种方式:对象冒充 function Parent(username){ this.username = username; this.hello = function(){ alert(this.username); } } function Child(username,password){ //通过以下3行实现将Parent的属性和方法追加到Child中,从而实现继承 //第一步:this.method是作为一个临时的属性,并且指向Parent所指向的对象, //第二步:执行this.method方法,即执行Parent所指向的对象函数 //第三步... 阅读全文
posted @ 2013-07-10 14:23 returnKing 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 工厂方式var oCar=new Object;oCar.color="red";oCar.doors=4;oCar.mpg=23;oCar.showCar=function(){ alert(this.colorr);};可能需要创建多个Car对象,所以可以封装在一个函数中,见代码function createCar(){var oTempCar=new Object;oTempCar.color="red";oTempCar.doors=4;oTempCar.mpg=23;oTempCar.showColor=function(){alert(thi 阅读全文
posted @ 2013-07-10 10:36 returnKing 阅读(263) 评论(0) 推荐(0) 编辑