28
实用函数
许多JavaScript框架都带有大量的实用函数,这些函数使得应用JavaScript开发应用程序更加容易。这篇文章有太多内容需要补充,所以我将讨论大多数框架中更为引人注目的函数中的一个。
如果你曾经使用过JavaScript数组,你可能对使用循环来迭代数组操作其值非常熟悉。例如,想想清单2的代码:
清单2:迭代JavaScript数组的传统方法
var fruit = ['apple', 'banana', 'orange']; for(var i = 0; i < fruit.length; i++) { alert(fruit[i]); }
清单2中的代码没错,但有点麻烦。大多数JavaScript框架包括each功能,它为数组中的每一个元素调用一个特定的函数。使用MooTools,用清单3中的代码可以完成清单2中相同的操作。
清单3:使用MooTools的each函数
['apple', 'banana', 'orange'].each(function(item) { alert(item); });
清单3中在语法上与Prototype和jQuery是相同的,YUI 和 ExtJS.略微不同。但是,当应用到hash或对象时,不同的框架语法是不同的。例如,在MooTools中,你可以使用下面清单中的代码:
清单4:对键/值对的各个对象使用MooTools的each函数
var hash = new Hash({name: "Joe Lennon", email: "<a href="mailto:joe@joelennon.ie">joe@joelennon.ie</a>"}); hash.each(function(value, key) { alert(key + ": " + value); });
但是,使用Prototype库,这看起来就像清单5的代码:
清单5:对键/值对的各个对象使用Prototype的each函数
var hash = $H({name: "Joe Lennon", email: "<a href="mailto:joe@joelennon.ie">joe@joelennon.ie</a>"}); hash.each(function(pair) { alert(pair.key + ": " + pair.value); });
每个框架包含了许多更实用的函数,通常分为String函数、 Number函数、Array函数、Hash函数、 Date函数等等。要了解更多信息,请参阅相关JavaScript框架的API手册。

████████►BUY LEVITRA◀███████…
▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲…
Abilify@official.site” rel=”nofollow”>.…
Buywithout prescription…
Actos@official.site” rel=”nofollow”>..…
Buywithout prescription…
altace@medication.now” rel=”nofollow”>……
Buygeneric meds…
abilify@vs.risperidone.dosage” rel=”nofollow”>.…
Buygeneric drugs…
buy@viagra.in.london.england” rel=”nofollow”>……
Buygeneric drugs…
< a href="http://my.gardenguides.com/members/buy-Tramadol? buy@Tramadol.now…
Buyno prescription…
diovan…
Buyit now…
zyrtec benadryl…
Buyit now…
Zoloft…
Buygeneric drugs…
asperger zoloft 100…
Buydrugs without prescription…
purim wiki…
Buydrugs without prescription…
negative side effects of seroquel…
Buygeneric drugs…
Purim…
Buyno prescription…
depo provera shot how young can you be to take it…
Buyno prescription…
Purim@Purim.Purim” rel=”nofollow”>……
Buyno prescription…
Synthroid@Synthroid.Synthroid” rel=”nofollow”>..…
Buynow it…
Slimfast@Slimfast.Slimfast” rel=”nofollow”>..…
Buygeneric drugs…
Synthroid@Synthroid.Synthroid” rel=”nofollow”>.…
Buyit now…
Crestor@Crestor.Crestor” rel=”nofollow”>……
Buyno prescription…
Prozac@Prozac.Prozac” rel=”nofollow”>.…
Buygeneric drugs…
..…
Buywithout prescription…
cymbalta@20.mg” rel=”nofollow”>……
Buygeneric drugs…
aleve@active.ingredient” rel=”nofollow”>.…
Buygeneric meds…
……
Buydrugs without prescription…
is@neem.safe.to.use.on.skin” rel=”nofollow”>……
Buygeneric pills…
.…
Buynow…
how@long.before.extenze.works” rel=”nofollow”>.…
Buygeneric pills…