這個例子是我在網上看到的例子:<script type="text/javascript">?var objectList2 = new Array();?function WorkMate(name,age){?this.name=name;?var _age=age;?this.age=function(){ //我實在是沒有看懂這里為什么要添加這樣一個方法if(!arguments) { //如果沒有實參傳入_age=arguments[0];} //那-age這個變量就被賦值為實參的第一個else {?return _age;} } } //否則返回-age這個變量objectList2.push(new WorkMate('jack',20));?objectList2.push(new WorkMate('tony',25));?objectList2.push(new WorkMate('stone',26));?objectList2.push(new WorkMate('mandy',23)); objectList2.sort(function(a,b){?return a.age()-b.age(); });?for(var i=0;i<objectList2.length;i++){?document.writeln('<br />age:'+objectList2[i].age()+' name:'+objectList2[i].name); }?</script>當中這段我備注的我不知道我理解的對嗎 ,麻煩大神幫我看一下。我想問一下這個方法到底有什么用呢?謝謝
求問一個數組sort方法的問題
Beckybei
2015-10-13 10:01:32