C#-[祈福]天佑中华 众志成城 抗震救灾 重建家园

你的苦难就是我们的苦难,你的希望就是我们的希望。当灾难来临时,我们与你在一起,一起为逝者默念安息、一起为伤者祈祷平安。而更多的关怀和力量,正悄悄在汇集:天佑中华,众志成城;抗震救灾、重建家园......
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Prototype通用性方法-invoke(methodName[, arg...]) -> Array

Posted on 2008-04-08 13:51  尹合磊  阅读(508)  评论(0编辑  收藏  举报
Optimization for a common use-case of each or collect: invoking the same method, with the same potential arguments, for all the elements. Returns the results of the method calls.

Since it avoids the cost of a lexical closure over an anonymous function (like you would do with each or collect), this performs much better. Perhaps more importantly, it definitely makes for more concise and more readable source code.

1 ['hello''world''cool!'].invoke('toUpperCase')
2 // ['HELLO', 'WORLD', 'COOL!']
3 
4 ['hello''world''cool!'].invoke('substring'03)
5 // ['hel', 'wor', 'coo']
6 
7 // Of course, this works on Prototype extensions (why shouldn't it?!)
8 $('navBar''adsBar''footer').invoke('hide')