function a(x){
alert(x)
}
function b(){
arguments[0] =1;
alert(arguments[0])
a.apply( this, arguments );
}
b()第一次弹出1貌似已经修改了
为什么a还是取不到呢

解决方案 »

  1.   

    function a(x){
        alert(x[0])
    }
    function b(){
        arguments[0] =1;
        alert(Object.prototype.toString.call(arguments) === "[object Array]")
        alert(arguments[0])
        a.apply( this, [arguments] );
    }
    b() apply第2个参数是数组  arguments不是数组//---------------------------
      

  2.   

    function a(x){
        alert(x);
        alert("len:" + x.length);
        alert('x[0]:'+ x[0]);
    }
    function b(){
        arguments[0] =1;//相当于是一个object的属性
        alert(arguments[0]);//1
        a(arguments);//object
        alert(typeof arguments);//object
        a.apply(this, [arguments]);//这里的arguments是一个array传递的
    }
    b();
    个人理解,仅供参考
      

  3.   

    function a(x){
    alert(x)
    }
    function b(){
    arguments[0] =1;
    alert(arguments.length)
    arguments.length=1
    a.apply( this, arguments );
    }
    b()这样就可以
    原来要手动修改length
      

  4.   


    ECMA 10.1.8 Arguments Object 最后有这么一段话
    In the case when arg is less than the number of formal parameters for the Function object, this property shares its value with the corresponding property of the activation object. This means that changing this property changes the corresponding property of the activation object and vice versa.
    深层可以理解为.只有虚参有相应实参对应时候.才具有共享作用.所以你的代码如果加个参数就可以了.
    function a(x){
        alert(x)
    }
    function b(){
        arguments[0] = 1;
        alert(arguments[0])
        a.apply( this, arguments );
    }
    b(0)
      

  5.   


    再给你一个例子
    function foo(a, b, c) {
        arguments[0] = 2;
        alert(a);
        
        c = 3;
    /*由于c没有对应的实参所以,此处不应共享应为undefined.但Chrome这个处理是个BUG.其余浏览器正常*/
        alert(arguments[2]); 
    }
    foo(1, 2);
      

  6.   


    我的问题跟你的这个不太一样
    我的是类数组的问题
    你加了参数后arguments.length就自动变成1了不过你说的共享问题我也不知道 学习了
      

  7.   

    标记一下。 原来要控制length 囧