为什么最后一个是递归? http://www.never-online.net/reference/Javascript/js-call-apply-caller-callee/有人能帮忙解释一下吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个不叫递归你的意思是不是要问为什么方法被改写了,然后继续写的按按钮的时候继承了上次的值?答案如下// advanced apply demofunction adApplyDemo(x) { //原始的adApplyDemo方法 return ("this is never-online, BlueDestiny '" + x + "' demo");}function handleAdApplyDemo(obj, fname, before) { //秘密在这里 var oldFunc = obj[fname]; //将传递进来的方法转换成对象数组,这里是this[adApplyDemo],实际上 //得到的是adApplyDemo 方法的指针 obj[fname] = function() { //动态的为adApplyDemo方法(指针)添加了方法 return oldFunc.apply(this, before(arguments)); //将参数before(arguments)传递给获得的指针对象//也就是adApplyDemo一开始的属性. 这里将hello world 传递给了adApplyDemo,然后将更改属性以后//的方法作为一个function绑定回adApplyDemo函数,这时候他就已经是hello world参数的函数了 };}function hellowordFunc(args) { args[0] = "hello " + args[0]; return args;}function applyBefore() { alert(adApplyDemo("world"));}function applyAfter() { handleAdApplyDemo(this, "adApplyDemo", hellowordFunc); alert(adApplyDemo("world")); // Hello world!} callee常用于对函数本身的匿名引用。 iframe如何获取纯文本内容 谁知道明道的前台用的是什么技术 浮动层,怎么不动? js 控制的 页面字体大小 问题 如何使IFRAME 中的超连接无效? 网页打印问题 关于js中调用绝对位置数值不成功的问题 关于下拉框的问题?急!!! 字符串截取方面的问题 jquery mobile 多选框无效 怎样防止自己站内文件被别人的站用iframe或者script调用? 帮忙说明一下这段代码,有关浮动广告图片的,谢谢
你的意思是不是要问为什么方法被改写了,然后继续写的按按钮的时候继承了上次的值?
答案如下// advanced apply demo
function adApplyDemo(x) { //原始的adApplyDemo方法
return ("this is never-online, BlueDestiny '" + x + "' demo");
}
function handleAdApplyDemo(obj, fname, before) { //秘密在这里
var oldFunc = obj[fname]; //将传递进来的方法转换成对象数组,这里是this[adApplyDemo],实际上
//得到的是adApplyDemo 方法的指针
obj[fname] = function() { //动态的为adApplyDemo方法(指针)添加了方法
return oldFunc.apply(this, before(arguments)); //将参数before(arguments)传递给获得的指针对象
//也就是adApplyDemo一开始的属性. 这里将hello world 传递给了adApplyDemo,然后将更改属性以后
//的方法作为一个function绑定回adApplyDemo函数,这时候他就已经是hello world参数的函数了
};
}
function hellowordFunc(args) {
args[0] = "hello " + args[0];
return args;
}
function applyBefore() {
alert(adApplyDemo("world"));
}
function applyAfter() {
handleAdApplyDemo(this, "adApplyDemo", hellowordFunc);
alert(adApplyDemo("world")); // Hello world!
}