function callMe(arg1, arg2){
var s = "";
s += "this value: " + this;
s += "<br />";
for (i in callMe.arguments) {
s += "arguments: " + callMe.arguments[i];
s += "<br />";
}
return s;
}
document.write("Original function: <br/>");
document.write(callMe(1, 2));
document.write("<br/>");
document.write("Function called with apply: <br/>");
document.write(callMe.apply(3, [ 4, 5 ]));
document.write(callMe.call(3, 4, 5 ));
// Output: // Original function: // this value: [object Window] // arguments: 1 // arguments: 2 // Function called with apply: // this value: 3 // arguments: 4 // arguments: 5
function zqz(a,b){
return alert(a+b);
}
function zqz_1(a,b){
zqz.apply(zqz_1,[a,b])
}
zqz_1(1,2) //->3
function add(a, b)
{
alert(a + b);
}
function sub(a, b)
{
alert(a - b);
}
add.call(sub, 3, 1); // 4
function zqz(a,b){
this.name=a;
this.age=b;
alert(this.name+" "+this.age);
}
function zqz_1(a,b){
zqz.apply(this,[a,b]) //我们亦可以这么写 zqz.apply(this,arguments)
}
zqz_1("Nic",12) //Nic 12
<input type="text" id="myText" value="input text">
function Obj(){
this.value="对象!";
}
var value="global 变量";
function Fun1(){
alert(this.value);
}
Fun1(); //global 变量
Fun1.call(window); //global 变量
Fun1.call(document.getElementById('myText')); //input text
Fun1.call(new Obj()); //对象!
Fun1(); //global 变量
var arr1=new Array("1","2","3");
var arr2=new Array("4","5","6");
Array.prototype.push.apply(arr1,arr2);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有