<script language=javascript>
var str="abc";
function xxx()
{
str = str.replace("a",function (){
var u=arguments[0];
return u;
}
);
}
xxx();
</script>
在上面代码中
arguments是指函数xxx的参数对象,还是 未命名函数function(){}的参数对象?
var str="abc";
function xxx()
{
str = str.replace("a",function (){
var u=arguments[0];
return u;
}
);
}
xxx();
</script>
在上面代码中
arguments是指函数xxx的参数对象,还是 未命名函数function(){}的参数对象?
var foo = function(){
alert(arguments.length);
alert(arguments[0]);
};foo('a','b');
</script>
function xxx()
{
str = str.replace("a",function (){return arguments[0];});
}
上面这个例子中的arguments是属于谁的?
选择:
1.函数xxx
2.replace函数
3.replace中的第二个参数:无名function()
{
str = str.replace("a",function (){return arguments[0];});
}上面这个例子中的arguments是属于谁的?
选择:
1.函数xxx
2.replace函数
3.replace中的第二个参数:无名function()
arguments = (nonamefunction.havearguments)?nonamefunction:xxx
感觉应该和变量的作用域差不多。
如2L所说,自己试一下不就知道了,我也去试一下。
http://w3school.com.cn/js/jsref_replace.asp
var str="abc";
function xxx()
{
str = str.replace("a",function (){
for(var i=0;i<arguments.length;i++){
alert(arguments[i]);
}
var u=arguments[0];
return u;
}
);
}
xxx();