ITeye博客

JavaScript

共 3 篇文章

JavaScript 类,对象

1. 构造函数方式 function Car(sColor,iDoors,iMpg) { this.color = sColor; this.doors = iDoors; this.mpg = iMpg; this.showColor = function() { alert(this.color); }; } Problem: 这种方式会导致每个对象都有自己的 showColor() . 2. 混合的构造函数/原型方式 function Car(sColor,iDoors,iMpg) { this.color = sColor; this.doors = iDoors; this.mpg…

2012-07-23 23:06 · JavaScript

JavaScript 继承

//父类 function ClassA(sColor) { //Define Properties this.color = sColor; this.drivers = new Array("Mike","John"); this.showColor = function() { prt(this.color); }; } //父类 function ClassB(sName) { this.name = sName; this.sayName = function () { prt(this.name); }; } //子类,多重继承父类 ClassA, ClassB function…

2012-07-23 22:58 · JavaScript

JavaScript 字符串连接

function StringBuffer () { this._strings_ = new Array(); } StringBuffer.prototype.append = function(str) { this._strings_.push(str); }; StringBuffer.prototype.toString = function() { return this._strings_.join(""); }; var str = new StringBuffer(); str.append("Audi"); str.append("BMW"); str.append("…

2012-07-23 20:32 · JavaScript