首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript apply步骤

2012-08-25 
javascript apply方法JavaScript的每个function对象都有一个apply方法语法如下:funtion.apply([thisObj[,a

javascript apply方法
JavaScript的每个function对象都有一个apply方法
          语法如下:funtion.apply([thisObj[,argArray]])
         功能说明:将一个函数的对象上下文从初始的上下文改变为由thisObj指定的新对象,用来模拟多态

/**method 声明**/function Object1(name) {        this.name = name;        this.fun1 = function(){        alert("this is first method !");        };        this.fun2 = function() {        alert("this is second method !");        };}function Object2(name) {        Object1.apply(this,[name]);        //Object1.apply(this,["hahahhah"]);}/**method 调用**/        var o2 = new Object2("china");        o2.fun1();     //alert("this is first method!");        o2.fun2();   //alert("this is second method!");        alert(o2.name+"==================apply method!");//alert(china=============apply method!); 





热点排行