Number.prototype.add = function (num){ return this+num; } function but1_click(){ alert((3).add(8)); }
function Car(cColor,cWeight){ this.cColor = cColor; this.cWeight = cWeight; } Car.prototype.drivers = new Array('zhangsan','lisi'); Car.prototype.work = function (cLong){ alert("我跑了"+cLong+"公里"); } function but2_click(){ var c = new Car("red","5"); c.drivers.push('zhaoliu'); alert(c.drivers); c.work(1); }
function Rectangle(rWeight,rHeight){ this.rWeight = rWeight; this.rHeight = rHeight; if( typeof this._init == 'undefined'){ Rectangle.prototype.test = function (){ alert("test"); } } this._init = true; } function but3_click(){ var t = new Rectangle(6,8); t.test(); }
function objectA(){ this.methodA = function (){ alert("我是A方法"); } } function objectB(){ this.methodB = function (){ alert("我是B方法"); } } objectB.prototype = new objectA(); function but4_click(){ var t = new objectB(); t.methodB(); t.methodA(); } script>