Higher order programming with JavaScript now even cooler
With the upcoming Firefox 1.1, a dozen of method will be introduced to the Array object. These includes every
, filter
, forEach
, indexOf
, lastIndexOf
, some
, and map
(not part of ECMAScript specification). You may need to take a look of higher order programming before proceeding this simple code example demonstrating the every
method:
function isBigEnough(element, index, array) { return (element >= 10); } passed = [12, 5, 8, 130, 44].every(isBigEnough); // passed is false passed = [12, 54, 18, 130, 44].every(isBigEnough); // passed is true
Sounds evil? Not. JavaScript was invented by Netscape, currently maintained by Mozilla, and will be continued to be improved by the Foundation. Like it or not, it is not intended to be a cross-browser scripting language. :-P
2 Comments:
Note that troll and spam comments will be deleted without any notification.
At 7/18/2005 11:17:00 pm, Anonymous said…
Every single one of the new methods being added to Firefox 1.1 can be achieved right now in plain ol' javascript by accessing the prototypes.
For example...
Array.prototype.each = function(fn){
for(var i = 0; i < this.length; i++){
fn(this[i]);
}
}
So, these additions by Mozilla are kind of silly. They are so easily and readily achieved by anyone who understands the prototype based language that is javascript.
At 7/18/2005 11:23:00 pm, minghong said…
But a native implementation is in no doubt better (faster) than JavaScript implementations.
Post a Comment
<< Home