demo1function ff(){
alert("1");
ff = function(){
alert("2");
}
}ff(); // output 1
ff(); // output 2
ff(); // output 2
ff(); // output 2
demo2function f(){
alert("1");
arguments.callee = function(){
alert("2");
}
}f(); // output 1
f(); // output 1
f(); // output 1
f(); // output 1
不能给 callee 赋值吗..并且 .如果demo1是一个匿名方法..那它的写法应该变成怎样的 ?
alert("1");
ff = function(){
alert("2");
}
}ff(); // output 1
ff(); // output 2
ff(); // output 2
ff(); // output 2
demo2function f(){
alert("1");
arguments.callee = function(){
alert("2");
}
}f(); // output 1
f(); // output 1
f(); // output 1
f(); // output 1
不能给 callee 赋值吗..并且 .如果demo1是一个匿名方法..那它的写法应该变成怎样的 ?
解决方案 »
- 求一段JS代码!能让链接直接调用JS函数达到管理链接地址的目的
- Easyui datagrid 如何取返回的参数
- JS怎么复制内容到剪切板?
- 请问<script src=和<script language= 的区别?
- 求一正则表达式:实现文本框限制“8位数字+1位字母+3位数字”
- div的宽度设置为width:100%,如果得到这个宽度的实际值?单位px?
- 如何知道框架中页面执行完毕,并且等待框架里面页面执行完毕再后执行后面代码
- 利用jquery easy ui 做的这页面框架问题
- 捕捉鼠标动作问题?解决即结贴,急急急
- radio点击以下选中,在点击恢复未选状态,怎么弄?
- 求css开发工具
- (高分求)javaScript : 实现IE多页面跳转控制
// 你第一个DEMO的理解就有问题了
function ff(){
alert("1");
aa = function(){
alert("2");
}
}ff(); // output 1
aa(); // output 2
aa(); // output 2
aa(); // output 2//-->
</script>
JavaScript不能动态修改自身的代码,这将非常邪恶~~~``如果一定要这样:
<script type="text/javascript">
function ff(){
alert(1);
for(var d in window){
if(window[d]==arguments.callee){window[d] = function(){alert(2);};}
}
}ff(); // output 1
ff(); // output 2</script>
alert('1');
ff = function() {
alert('2');
};
})();
2. 对于demo2,如果arguments.callee不能被赋值的话,那么demo2在执行的时候很显然会报错。所以,既然你连续调用四次函数f都没有错误的话,那么可以得出结论:arguments.callee是可以被赋值的。
但是在demo2中你对arguments.callee的操作是完全没有意义的。我知道你的本意,既然你知道arguments.callee保存的是当前函数的引用,那么你去改变它,只会改变它的指向罢了,对于函数f来说没有一点影响,因为:你改变的只是arguments.callee的引用,没有改变函数f的引用。
故而四次调用f输出结果的都是1也就不足为奇了。
function ff() {
alert(1);
// 给 arguments.callee 赋值
arguments.callee = function() {
alert(2);
};
// 试执一下
arguments.callee(); // 看到2, 说明赋值成功.
}
ff();
function ff() {
// ff 跟 arguments.callee 都指向同一个函数
alert(ff == arguments.callee); // 看到 true // 给 arguments.callee 赋值, 这个赋值是成功的, 但只改变 arguments.callee
arguments.callee = function() {
alert(2);
}; // 没有改变 ff 的指向
alert(ff == arguments.callee); // false
}
ff();