JavaScript

   


Robust ㄧ计


arguments 皚

セ呼顶毙厩矗のㄧ计 常琌Τ㏕﹚计ヘ把计 Τぃ穦笵ㄧ计穦Τぶ把计 ê或快㎡

氮碞琌ㄏノㄧ计 arguments 皚ㄓボ把计 硂妓碞琵ㄧ计钡ぃ计ヘ把计 τ硂贺ㄧ计碞嘿 Robust ㄧ计

ㄒ arguments 皚

<script>
function sum() {
var total = 0;
var len = sum.arguments.length;
if (len == 0) {
  return null
}
else {
  for (i=0 ; i < len ; i++) total += sum.arguments[i]
  return total
}
}

document.write("<br>" + sum());
document.write("<br>" + sum(1,2));
document.write("<br>" + sum(1,2,3,4,5,6,7));
</script>

弧

  • sum.arguments.length

    ボ sum ㄧ计Τぶ把计

  • sum.arguments[i]

    讽 i 单 0  碞材把计 ㎝炊硄皚阀├妓

ㄒ ノ arguments 皚箇更 Image

<script>
var myimages=new Array()
function preloadimages(){
for (i=0 ; i < preloadimages.arguments.length ; i++){
  myimages[i] = new Image()
  myimages[i].src = preloadimages.arguments[i]
}
}

preloadimages("0.gif","1.gif","2.gif")
</script>

ノ皚蠢 Robust ㄧ计

ノ Robust ㄧ计钡ぃ计ヘ把计 狦ㄧ计璶肚ぃ计ヘ ê或快㎡ 程虏虫よ猭碞琌ㄏノ皚

ㄒ 盢块皚じ锣 礛肚

<script>
function reverse(aray) {
var len = aray.length
var temp
if (len ==0) {
  return null
}
else {
  for (i=0 ; i < len/2 ; i++) {
   temp = aray[i]
   aray[i] = aray[len-i-1]
   aray[len-i-1] = temp
  }
return aray
}
}

var test = new Array()
document.write("<br>" + reverse(test));
test[0] = 1
document.write("<br>" + reverse(test));
test = Array(1,2,3,4)
document.write("<br>" + reverse(test));
test = Array(1,2,3,4,5)
document.write("<br>" + reverse(test));
</script>

ノ Robust ㄧ计ゑㄏノ皚耕よ獽 狦ノ皚 ê或ㄧ计碞Τ把计 碞琌赣皚 τ皚ずじゲ斗琌篈 и块篈狥﹁ㄧ计ず  Robust ㄧ计碞钡ぃ篈把计 τ糶猭ゑ耕虏獽







[郴] [] [硉琩]