<script>
function
SortNumber(obj,func)
{
if
(!(obj
instanceof
Array) || !(func
instanceof
Function))
{
var
e =
new
Error();
e.number = 100000;
e.message =
"参数无效"
;
throw
e;
}
for
(n
in
obj)
{
for
(m
in
obj)
{
if
(func( obj[n],obj[m]) )
{
var
tmp = obj[n];
obj[n] = obj[m];
obj[m] = tmp;
}
}
}
return
obj;
}
function
greatThan(arg1,arg2)
{
return
arg1 < arg2;
}
try
{
var
numAry =
new
Array(5,8,6,32,1,45,6,89,9);
document.write(
"<li>排序前:"
+numAry);
SortNumber(numAry,greatThan);
document.write(
"<li>排序后:"
+numAry);
}
catch
(e)
{
alert(e.number+
":"
+e.message);
}
</script>