arguments.slice ?


    Apr 20 2006 | 11:16 pm
    Hi,
    ths probably has to do with my still sketchy knowledge of javascript,
    but i don't understand why within a function this does not work:
    index = addToPalette(arguments.slice(2,5));
    while this does:
    index = addToPalette(arguments[2], arguments[3], arguments[4]);
    the first line give me the error that arguments.slice is not a
    function, which is weird, no ?
    isn't the arguments property an array (so that I can call the 'slice'
    method on it ??)
    ciao,
    Joost.
    -------------------------------------------
    Joost Rekveld
    -------------------------------------------
    "The mystery of the world is the visible, not the invisible"
    (Oscar Wilde)
    -------------------------------------------

    • Apr 20 2006 | 11:23 pm
      sorry,
      the second line should be:
      index = addToPalette([arguments[2], arguments[3], arguments[4]]);
      (not the extra square brackets)
      J.
      -------------------------------------------
      Joost Rekveld
      -------------------------------------------
      "The mystery of the world is the visible, not the invisible"
      (Oscar Wilde)
      -------------------------------------------
    • Apr 20 2006 | 11:46 pm
      On Apr 20, 2006, at 4:16 PM, Joost Rekveld wrote:
      > the first line give me the error that arguments.slice is not a
      > function, which is weird, no ?
      > isn't the arguments property an array (so that I can call the
      > 'slice' method on it ??)
      The arguments object is technically *not* an array, despite being
      indexable as one. Note the wording "array-like" in the Core
      Javascript 1.5 Guide:
      http://developer.mozilla.org/en/docs/
      Core_JavaScript_1.5_Guide:Using_the_arguments_object
      This is why we've provided the arrayfromargs utility method which
      converts an arguments object to a true array. Basically it does the
      following, though from C:
      function arrayfromargs(args)
      {
      var myarray = new Array();
      var i;
      for (i=0;i myarray[i] = args[i];
      return myarray;
      }
      -Joshua
    • Apr 21 2006 | 12:01 am
      thanks, now I get it..
      -------------------------------------------
      Joost Rekveld
      -------------------------------------------
      "The mystery of the world is the visible, not the invisible"
      (Oscar Wilde)
      -------------------------------------------