Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Possible bug in isc.List.contains

    I am not sure I understand well how isc.list.contains is supposed to work. Using V8.0 seems to yield different results using contains VS containsAll. You can use this code to test it out:

    Code:
    ll = isc.List.create([{AreaCode: '123'}]);
    FoundOne = ll.contains({AreaCode: '123'});
    FoundList = ll.containsAll(isc.List.create([{AreaCode: '123'}]));
    
    isc.say(FoundOne + ', ' + FoundList);
    In the code above, contains returns false, while containsAll returns true. The prompt says "false, true".

    Anything I am missing, or is it a bug?

    Thanks,
    Sorin
    Last edited by vina; 9 Feb 2011, 02:44.

    #2
    Further testing reveals that containsAll returns true even if ran against an empty list: Here's a test case:

    Code:
    ll = isc.List.create([]);
    FoundList = ll.containsAll(isc.List.create([{AreaCode: '123'}]));
    
    isc.say(FoundList);

    Comment


      #3
      List is an Interface, which you can think of as similar to a Java AbstractClass. It will have unexpected behaviors if you haven't implemented the methods necessary to complete the implementation.

      Concrete implementations are ResultSet and Tree, and the JavaScript native Array is also retrofitted to support the List interface.

      Comment


        #4
        Thanks for the clarification. I thought all methods are implemented.

        I posted this example in an effort to create the simplest test case.

        I actually got here from getting the same behavior on the ListGrid.data implementation of the List class. I was using a ListGrid with local data supplied via the data member and I tried to check whether it contains such an object. While one may argue that using a construct such as {AreaCode: '123'} in two different places will yield two different objects that are not equal, a concrete usage scenario would often requires such checking. So it might make sense to make the List (and to a larger extent the Array) check against the object properties instead of performing a simple comparison. Maybe supply a different method?

        Of course, this is just a suggestion on how the framework support for the built in JS objects can be improved.

        For people running into this thread, the simplest solution to this is to iterate yourself the array or list and compare each object property that interests you. Or, if you want to get fancy, use the function posted here: http://stackoverflow.com/questions/1068834/object-comparison-in-javascript

        Comment


          #5
          Sorry, no, the original test case was wrong. contains() works by object identity, not matching properties, and this is as it should. Use find() to find objects by matching properties, no need for iteration.

          Comment


            #6
            Ah, thanks for pointing that out. I completely missed that method. Glad to see it was already built in.

            Comment

            Working...
            X