<script type="text/javascript">
//<![CDATA[ function Old()
{
alert("Old-arguments.length: "+arguments.length);
New.apply(this, arguments);
}
function New()
{
alert("New-arguments.length: "+arguments.length);
}
Old(1,2,3,4,5);
//]]>
</script>
//<![CDATA[ function Old()
{
alert("Old-arguments.length: "+arguments.length);
New.apply(this, arguments);
}
function New()
{
alert("New-arguments.length: "+arguments.length);
}
Old(1,2,3,4,5);
//]]>
</script>
但数组在参数中只是一个参数, 要传递数组元素为参数的话, 就使用 apply 实现....
function fun(){
alert(arguments[0]);
alert(arguments[1]);
alert(arguments[2]);
alert(arguments[3]);
}
fun(1,2,3,4);
fun("a","b","c","d");
</script>arguments类似一个数组,但不同于Array,没有Array的方法~~~
//搞清楚了:这里的arguments是其所在的匿名函数的arguments
function bindMethod(o, f)
{
return function()
{
return f.apply(o, arguments);
}
}
//试验代码:
function oo ()
{
this.t="o ";
}function ff ()
{
alert(this.t+arguments.callee+arguments[0]+arguments[1]+arguments[2]);
}var n, m, t="? ";
m=new oo(1,2,3);
n=bindMethod(m, ff) ;
n(4,5,6);//<==>ff.apply(this, [4,5,6]);
ff.apply(this, [4,5,6]);
//注意观察两次this.t的内容有何不同!
</script>
n(4,5,6);//<==>ff.apply(m, [4,5,6]);
另外,可不可以这样理解:在浏览器里dom和css就相当于c/c++的gdi图形界面库?
obj[stringKey] || obj[integerKey]
看起来更像哈希表...GDI...
浏览器都是排版引擎...
I.E. xxx layout engine...