HighDots Forums  

A.sort(null) IE and non-IE

Javascript JavaScript language (comp.lang.javascript)


Discuss A.sort(null) IE and non-IE in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ddailey
 
Posts: n/a

Default A.sort(null) IE and non-IE - 01-03-2008 , 12:27 PM






For reasons that are rather complicated, I have provided my JavaScript
sort() method of an array with the null parameter (rather than an
empty parameter list).

A=[2,3,8,4,1,0]
alert(A.sort(null))

In Opera, FF and Safari, A.sort(null) returns the same array as A, but
IE actually performs the default ascii-order sort. I would assume the
majority of browsers here are following the ECMA-script standard. Is
IE's behavior here a bug?

Reply With Quote
  #2  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: A.sort(null) IE and non-IE - 01-03-2008 , 12:58 PM






ddailey wrote:
Quote:
A=[2,3,8,4,1,0]
alert(A.sort(null))

In Opera, FF and Safari, A.sort(null) returns the same array as A, but
IE actually performs the default ascii-order sort. I would assume the
majority of browsers here are following the ECMA-script standard. Is
IE's behavior here a bug?
It isn't:

Quote:
If comparefn is not undefined and is not a consistent comparison
function for the elements of this array (see below), the behaviour
of sort is implementation-defined. [...]
Simply don't pass `null' as argument:

Quote:
15.4.4.11 Array.prototype.sort (comparefn)

The elements of this array are sorted. The sort is not necessarily stable
(that is, elements that compare equal do not necessarily remain in their
original order). If comparefn is not undefined, it should be a function
that accepts two arguments x and y and returns a negative value if x < y,
zero if x = y, or a positive value if x > y.

PointedEars


Reply With Quote
  #3  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: A.sort(null) IE and non-IE - 01-03-2008 , 01:19 PM



Thomas 'PointedEars' Lahn wrote:
Quote:
ddailey wrote:
A=[2,3,8,4,1,0]
alert(A.sort(null))

In Opera, FF and Safari, A.sort(null) returns the same array as A, but
IE actually performs the default ascii-order sort. I would assume the
majority of browsers here are following the ECMA-script standard. Is
_ECMAScript_

Quote:
IE's behavior here a bug?

It isn't:
[...]
Besides, you have not tested carefully enough.

Test case
----------

var a = [2, 3, 8, 4, 1, 0];
window.alert(a.sort(null));
window.alert(a);

Results
--------

Opera/9.24 (Windows NT 5.1; U; en):

0,1,2,3,4,8
0,1,2,3,4,8

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127
Firefox/2.0.0.11:

Error: TypeError: invalid Array.prototype.sort argument
Code: window.alert(a.sort(null));
Line: 2

(no message window)

Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE) AppleWebKit/523.15 (KHTML,
like Gecko) Version/3.0 Safari/523.15:

Error: TypeError: Null value
Line: 2

(no message window)


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
  #4  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: A.sort(null) IE and non-IE - 01-04-2008 , 12:08 PM



In comp.lang.javascript message <f735447e-98a7-4235-b710-fa8cb17cec56@m3
4g2000hsf.googlegroups.com>, Thu, 3 Jan 2008 10:27:20, ddailey
<ddailey (AT) zoominternet (DOT) net> posted:
Quote:
For reasons that are rather complicated, I have provided my JavaScript
sort() method of an array with the null parameter (rather than an
empty parameter list).

A=[2,3,8,4,1,0]
alert(A.sort(null))

In Opera, FF and Safari, A.sort(null) returns the same array as A, but
IE actually performs the default ascii-order sort. I would assume the
majority of browsers here are following the ECMA-script standard. Is
IE's behavior here a bug?

The standard is unclear. One cannot tell whether, by 'undefined', it
means 'not-defined' or it means 'the value that U has after var U ;' .
It's also not clear to me whether the standard says what should result
if no argument, or an argument like U, is given.

If you've not done so, it might be worth trying the use of U rather than
null.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.