Loading ...
Sorry, an error occurred while loading the content.

Re: Type confusion, array and object

Expand Messages
  • Douglas Crockford
    ... JSLint now gives the warning on line 1. There is confusion with array.filter.
    Message 1 of 8 , Jun 21, 2011
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "tom.haggie" <tom.haggie@...> wrote:

      > Here's a simple way to get type confusion with arrays:
      >
      > var obj = {filter: ["me"]};
      >
      > var item = obj.filter[1];

      JSLint now gives the warning on line 1.
      There is confusion with array.filter.
    • tom.haggie@sap.com
      ... But it s an object not an Array
      Message 2 of 8 , Jun 22, 2011
      • 0 Attachment
        > There is confusion with array.filter.

        But it's an object not an Array
      • Luke Page
        ... Because array.filter is a provided function a user looking at a.filter() would be likely to assume a is an array. This could lead to errors or lost time.
        Message 3 of 8 , Jun 22, 2011
        • 0 Attachment
          >
          > > There is confusion with array.filter.
          >
          > But it's an object not an Array
          >

          Because array.filter is a provided function a user looking at a.filter()
          would be likely to assume a is an array. This could lead to errors or lost
          time. (That is the logic anyway)


          [Non-text portions of this message have been removed]
        • tom.haggie@sap.com
          So the answer is that the name space should be considered global because filter is used somewhere it can t be used anywhere else? Originally some sort of
          Message 4 of 8 , Jun 22, 2011
          • 0 Attachment
            So the answer is that the name space should be considered global because filter is used somewhere it can't be used anywhere else?

            Originally some sort of rudimentary type checking sounded useful but I think I'm going to I'm going to opt out if this is the direction it's going.
          Your message has been successfully submitted and would be delivered to recipients shortly.