排序问题,如何理解函数 function sortNum(a,b) {return b-a;},这表示重写底层函数吗?
如何理解函数 function sortNum(a,b) {return b-a;},这表示重写底层函数吗?另外document.write(myarr.sort(sortNum));中sortNum表示函数为什么不写成sortNum()呢?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array对象 </title>
<script type="text/javascript">
function sortNum(a,b) {
return b-a;
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
</script>
</head>
<body>
</body>
</html>