apply 方法
请参阅
应用于:Function 对象
要求
版本 5.5
应用某一对象的一个方法,用另一个对象替换当前对象。apply([thisObj[,argArray]])
参数
thisObj 
可选项。将被用作当前对象的对象。 
argArray 
可选项。将被传递给该函数的参数数组。 
说明
如果 argArray 不是一个有效的数组或者不是 arguments 对象,那么将导致一个 TypeError。如果没有提供 argArray 和 thisObj 任何一个参数,那么 Global 对象将被用作 thisObj, 并且无法被传递任何参数。call 方法
请参阅
应用于:Function 对象
要求
版本 5.5
调用一个对象的一个方法,以另一个对象替换当前对象。call([thisObj[,arg1[, arg2[,   [,.argN]]]]])
参数
thisObj 
可选项。将被用作当前对象的对象。 
arg1, arg2, , argN 
可选项。将被传递方法参数序列。 
说明
call 方法可以用来代替另一个对象调用一个方法。call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象。如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj。

解决方案 »

  1.   

    1.apply和call可以看看这篇文章,会明白其中的机理的
    http://blog.csdn.net/fason/archive/2004/07/30/apply_call.aspx2.selection.createRange是从当前的选择文件中生成一个textrange
      

  2.   

    2.selection.createRange是从当前的选择文件中生成一个textrange
    当前的选择文件是指什么?
    不论从哪里生成textrange对象操作不都是一样的吗.
    有什么区别吗?
      

  3.   

    打错字,是选择文本,不是文件
    obj.createTextRange()产生的textrange对象默认范围在对文本的开始和结束处
      

  4.   

    看了fason的程序有点理解了.
    感觉apply和call实现的功能是差不多的.只是apply的参数是作为数组或arguments对象来传递的.
    而call是将参数单个传递的.
    我记得fason的贴子中有这么一句
    var agu = Array.prototype.slice.call(arguments,1);
    我理解为取得当前函数arguments[1]-arguments[n]并返回一个数组
    是不是和下面的语句是一样的
    var arg = new Array();
    for(i=0;i<arguments.length;i++)
       arg[i] = arguments[i];
    var agu = arg.slice(1);
    ------------------------------
    不太明白的是arguments既然是一个对象,又怎么能使用Array的方法呢?
      

  5.   

    看看这贴后面的讨论http://community.csdn.net/Expert/topic/3191/3191873.xml?temp=.3663446
      

  6.   

    <script>// the class
    function cal()
    {
    this.add = function (x, y)
    {
    return x + y;
    }
    }
    // the object to apply
    var ins_tmp = new cal();// the function
    function b()
    {
    // notice: without the apply method, what is 'this' below?
    alert(this.add(arguments[0], arguments[1]));
    }// arguments(parameters).
    var args = new Array();args[0] = 1;
    args[1] = 3;// try directly call the function 'b()'
    // notice the error message in the error dialog box.
    b.apply(ins_tmp, args);</script>
      

  7.   

    function a()
    {
    this.hello = function ()
    {
    alert("Hello world");
    }
    }function b()
    {
    a.call(this);
    }new b().hello();
      

  8.   

    最简版,有助于理解。function a()
    {
    alert("hello world");
    }function b()
    {
    a.call();
    }b();
      

  9.   

    javascript在一个function上做出了很大的文章,这个也说不太好,主要还是可以通过这些东西来实现一些面向对象的机制。
      

  10.   

    查了一下.好像应用到对象的继承方面比较多一些.
    不过继承使用b.prototype = a; 也是可以实现的.
    不知道还有没有别的方面的应用..
      

  11.   

    http://blog.csdn.net/fason/archive/2004/07/30/settimeout.aspx