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

Re: [jslint] Type confusion, array and object

Expand Messages
  • Luke Page
    In your example, x is not an array, it is an object. replacing var x = {foo : bar }; with var x = [ foo ]; would work. ... [Non-text portions of this message
    Message 1 of 8 , Jun 21, 2011
      In your example, x is not an array, it is an object.

      replacing

      var x = {foo : 'bar'};

      with

      var x = ['foo'];

      would work.

      On 21 June 2011 15:37, s_lubowsky <slubowsky@...> wrote:

      > **
      >
      >
      > In version 2011-06-20 trying to get an object out of an array causes a type
      > confusion error to be flagged. Why would this be a problem? If it is a
      > potential problem, how would I do this "correctly"
      >
      > For example the following code causes the error 'Problem at line 9
      > character 14: Type confusion: array and 'x': object.'
      >
      > var x = {foo : 'bar'};
      >
      > function foobar() {
      > 'use strict';
      >
      > var it,
      > i;
      > for (i = 0; i < x.length; i += 1) {
      > it = x[i];
      > }
      > }
      >
      > Thanks.
      >
      >
      >


      [Non-text portions of this message have been removed]
    • s_lubowsky
      Yes, I made a typo when I tried to reproduce the bug in a simple example. In my actual more complex case I get the error without any obvious problem. I am
      Message 2 of 8 , Jun 21, 2011
        Yes, I made a typo when I tried to reproduce the bug in a simple example. In my actual more complex case I get the error without any obvious problem. I am still trying to reproduce it in a simpler case. If I succeed I will repost.

        Thanks

        --- In jslint_com@yahoogroups.com, Luke Page <luke.a.page@...> wrote:
        >
        > In your example, x is not an array, it is an object.
        >
        > replacing
        >
        > var x = {foo : 'bar'};
        >
        > with
        >
        > var x = ['foo'];
        >
        > would work.
        >
        > On 21 June 2011 15:37, s_lubowsky <slubowsky@...> wrote:
        >
        > > **
        > >
        > >
        > > In version 2011-06-20 trying to get an object out of an array causes a type
        > > confusion error to be flagged. Why would this be a problem? If it is a
        > > potential problem, how would I do this "correctly"
        > >
        > > For example the following code causes the error 'Problem at line 9
        > > character 14: Type confusion: array and 'x': object.'
        > >
        > > var x = {foo : 'bar'};
        > >
        > > function foobar() {
        > > 'use strict';
        > >
        > > var it,
        > > i;
        > > for (i = 0; i < x.length; i += 1) {
        > > it = x[i];
        > > }
        > > }
        > >
        > > Thanks.
        > >
        > >
        > >
        >
        >
        > [Non-text portions of this message have been removed]
        >
      • tom.haggie
        Here s a simple way to get type confusion with arrays: var obj = {filter: [ me ]}; var item = obj.filter[1];
        Message 3 of 8 , Jun 21, 2011
          Here's a simple way to get type confusion with arrays:

          var obj = {filter: ["me"]};

          var item = obj.filter[1];
        • Luke Page
          as in previous posts x is probably used in a different function to mean an object... ... [Non-text portions of this message have been removed]
          Message 4 of 8 , Jun 21, 2011
            as in previous posts x is probably used in a different function to mean an
            object...

            On 21 June 2011 16:16, s_lubowsky <slubowsky@...> wrote:

            > **
            >
            >
            > Yes, I made a typo when I tried to reproduce the bug in a simple example.
            > In my actual more complex case I get the error without any obvious problem.
            > I am still trying to reproduce it in a simpler case. If I succeed I will
            > repost.
            >
            > Thanks
            >


            [Non-text portions of this message have been removed]
          • Douglas Crockford
            ... JSLint now gives the warning on line 1. There is confusion with array.filter.
            Message 5 of 8 , Jun 21, 2011
              --- 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 6 of 8 , Jun 22, 2011
                > 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 7 of 8 , Jun 22, 2011
                  >
                  > > 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 8 of 8 , Jun 22, 2011
                    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.