JavaSam 发表于 2013-1-29 08:42:03

javascript 学习笔记

《一》。利用arguments对象可以模拟函数重载

例:function  addition(){

           if(arguments.length == 1){


           }else if (arguments.length == 2) {


           }



调用:addition (args1),addition(args1,args2);

《二》。javascript继承实现的方式

        a》。对象冒充

        b》。原型链

        c》。混合方式
 
 
 
    javascript
<div class="quote_div">//多边形
function Ploygon(iSides) {
this.sides = iSides;
//多边形的边数
}

Ploygon.prototype.getArea = function() {
return 0;
//占位符,以被子类覆盖
}
/**
*三角形
* @param {Object} iBase
* @param {Object} iHeight
*/
function Triangle(iBase, iHeight) {
Ploygon.call(this, 3);
//继承父类方法
this.base = iBase;
this.height = iHeight;
}

Triangle.prototype = new Ploygon();
//继承
//重写方法
Triangle.prototype.getArea = function() {
return 0.5 * this.base * this.height;
}
function Rectangle(iLenght, iWidth) {
Ploygon.call(this, 4);
this.length = iLenght;
this.width = iWidth;
}

Rectangle.prototype = new Ploygon();
Rectangle.prototype.getArea = function() {
return this.length * this.width;
}
页: [1]
查看完整版本: javascript 学习笔记