var util=(function () { return{ extend:function (subClass,supClass) { function F() {} F.prototype=supClass.prototype; subClass.prototype=new F(); subClass.prototype.constructor=subClass; subClass.superClass=supClass; if(subClass.prototype.constructor===Object.prototype.constructor){ supClass.prototype.constructor=supClass } }, appendPrototype:function (target,source) { var names=Object.getOwnPropertyNames(source); for(var i=0;i<names.length;i++){ var proto=Object.getOwnPropertyDescriptor(source,names[i]); Object.defineProperty(target,names[i],proto) } } } })(); (function (win) { function DivElem(bg) { this.div=document.createElement("div"); util.appendPrototype(this.div,DivElem.prototype); this.setBgColor(bg); return this.div; } DivElem.prototype={ _width:0, _height:0, set width(value){ this._width=value; this.style.width=value+"px"; }, get width(){ return this._width; }, set height(value){ this._height=value; this.style.height=value+"px"; }, get height(){ return this._height; }, setBgColor:function (bg) { this.div.style.backgroundColor=bg; this.div.style.transform="rotate(60deg)"; } }; function BgDivElem(bg) { DivElem.call(this,bg); return this.div } util.extend(BgDivElem,DivElem); BgDivElem.prototype.setBgColor=function (bg) { BgDivElem.superClass.prototype.setBgColor.call(this,bg); this.div.style.border="5px solid #000000" }; win.BgDivElem=BgDivElem; win.DivElem=DivElem; })(window);
js 继承 实例
最新推荐文章于 2024-07-26 09:48:00 发布