奇怪的 Arguments 对象

/*
注意每个浏览器的实现方式不同,他们处理的方法也不同.
官网原文:
      There is no uniform handling of a variable named arguments amongst the various script engine implementations.
    Example:
*/
<script> 
    function foo() 
    { 
         document.write(arguments); 
         document.write(arguments[0]); 
         eval("arguments = 10;"); 
         document.write(arguments); 
         document.write(arguments[0]); 
    } 
    foo("test"); 
</script> 
/*
      Output: 
            IE: [object Object]test[object Object]test 
            FF: [object Object]test10undefined 
            Opera: testtest10undefined 
            Safari: [object Arguments]test10undefined 
[color=red]Note:[/color] 
     Refer §10.1.6 - arguments is added as a {DontDelete} property to the “variable object” before the variable instantiations steps (§10.1.3) take place. Now, consider the following: 
*/
<script> 
      function foo()  
      { 
           document.write(arguments); 
           document.write(arguments[0]); 
           arguments = 10; 
           document.write(arguments); 
           document.write(arguments[0]); 
      } 
      foo(42); 
</script>
/*
 And here is the outputs: 
                IE: [object Object]4210undefined 
                FF: same as IE 
                Opera: 424210undefined 
                Safari: [object Arguments]4210undefined 
[color=red]Note: [/color]
     In JScript arguments isn‟t included in the variable context that is used by the eval, so the eval‟ed assignment isn‟t actually changing the value of the enclosing functions arguments variable.
*/

你可能感兴趣的:(浏览器,IE,Opera,Safari)