87,916
社区成员
发帖
与我相关
我的任务
分享
function ff(){
alert("1");
ff = function(){
alert("2");
}
}
ff(); // output 1
ff(); // output 2
ff(); // output 2
ff(); // output 2
function f(){
alert("1");
arguments.callee = function(){
alert("2");
}
}
f(); // output 1
f(); // output 1
f(); // output 1
f(); // output 1
<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>
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();
(function() {
alert('1');
ff = function() {
alert('2');
};
})();
// 你第一个DEMO的理解就有问题了
function ff(){
alert("1");
aa = function(){
alert("2");
}
}
ff(); // output 1
aa(); // output 2
aa(); // output 2
aa(); // output 2
//-->
</script>