At 01:27 31/05/2001, you wrote:
>I'm trying to sort based on the object's name so the call looks like this:

Could you develop ? I do not understand what you exactly mean by "object's 
name". Do you mean you have a field "name" inside every object of the array ?


>arrToSort.sort( compare )
>
>function compare( a, b ) { return a.name - b.name; }

This will never work this way, as Javascript is unable to substract to Strings.

>This doesn't work ( obviously ), and I can't seem to figure it out. Does
>anyone out there know how to do this or know of some documentation that can
>point me in the right direction?

I suppose you've read this ? 
http://developer.netscape.com/docs/manuals/js/core/jsref15/array.html#1196882

IMHO, as stated by "Digital Strider", the best way for not to reivent the 
wheel is not to priovide any compare function while sorting. You should 
just write the appropriate toString() method for your objects, so they are 
properly converted to strings by the default compare function used in sort().
for example

         myObject.prototype.toString = function() {
                 return this.nameOfTheObject;
         }

I think this would work, but never tested it as far as I rmember

Marc


_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help

Reply via email to