六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

javascript 学习笔记

[复制链接]

升级  39.33%

29

主题

29

主题

29

主题

秀才

Rank: 2

积分
109
 楼主| 发表于 2013-1-29 08:42:03 | 显示全部楼层 |阅读模式
《一》。利用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;
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表