Mozilla Extending Javascript?
Nomad128 writes "Mozilla's Deer Park 1 Alpha RC appears to have extended the Javascript spec for the first time in quite some time. New features include Array object methods "every" (logical AND), "some" (logical OR), "map" (function mapping), and "forEach" (iteration). They also appear to have added native XML support. Will this speed up the development of AJAX applications and give Moz a leg-up over IE7?"
If they are useful for people developing on the "mozilla platform", then they are useful features. For example, Firefox and Thunderbird, and extensions to each, can use these new features. They can't be used in web pages unless you want them to be Mozilla-only, of course.
Napster-to-go says "Fill and refill your compatible MP3 player", which is a lie. It's not MP3. It's WMA with DRM.
If you're on Windows, I'd strongly recommend Proxomitron - a kickass personal web proxy that is able to strip out all the crap. If you're on Linux, there's Privoxy, or you could just use Greasemonkey (although that's possibly overkill).
For the love of God, please learn to spell "ridiculous"!!!
Sorry, the link was http://developer-test.mozilla.org/docs/Drawing_Gra phics_with_Canvas
C'mon, mods, the parent poster makes a good point. It's only "flamebait" if you're ready to apologize for the hypocrisy of the Mozilla developers.
For the record, the new methods are NOT ECMA standards, according to the Array object reference. In other words, developers relying on these methods will be locking themselves into Gecko, unless other vendors scramble to support them, which they will likely do in buggy and incomplete ways--which, incidentally, is exactly what standards (like ECMAScript) were supposed to prevent.
I suspect we'll be seeing similar non-standard extensions to CSS and (X)HTML in the months and years to come, rendering the W3C more and more irrelevant. The standards armistice was always a nice dream, I guess, and it was good while it lasted. So much for that.
I would like to second the parent's comments on SVG. I am extremely pumped this spec to be included by default in the next version of Firefox.
I would like to add another use to the list, though. Having an SVG canvas to use for XUL apps will be a blast to play around with. As a weather nerd, I can't wait to create XUL web apps with a GIS backend that uses SVG to describe the map and weather data. Combining the XUL widgets with a vector based canvas area will be quite the combination.
That said, I believe quite a few of these new extensions will come in handy when starting to program for these things. I, for one, welcome our new Javascript extension overlords...
Bryan R.
The price of freedom is eternal vigilance, or $12.50 as seen on eBay.....
Well, I only had a quick look, but these extensions don't appear to be very difficult to reproduce in other browsers...
The following mimics the forEach extension - and works in Mozilla, Opera and IE
Array.prototype.forEach = function(fn) {
for(var i =0; i this.length; ++i) {
fn(this[i], i, this);
}
}
function foo(obj, index, array) {
alert("index " + index + " is " + obj);
}
[4,5,6].forEach(foo);
(Only had a quick look at the Mozilla article and 5 mins knocking the source up, so excuse any silly errors)
Ditto for "map". Actually I didn't notice they also specified an optional "this object" for forEach()...
Array.prototype.map = function(fn, array) {
var thisObject = array == undefined ? this : array;
var result = [];
for(var i =0; i thisObject.length; ++i) {
result.push(fn(thisObject[i]));
}
return result;
}
function makeUpperCase(obj) {
return obj.toUpperCase();
}
strings = [ "hello", "Array", "WORLD" ];
uppers = strings.map(makeUpperCase);
alert(uppers);
alert(strings);
ECMA spec allows you to add in anything you want...
A conforming implementation of ECMAScript is permitted to provide additional types, values, objects,
properties, and functions beyond those described in this specification. In particular, a conforming
implementation of ECMAScript is permitted to provide properties not described in this specification, and
values for those properties, for objects that are described in this specification.
You're failing to distinguish between the language and implementations of the language.
By analogy, the C++ language has changed once since 1997 (with the technical corrigendum that fixed a couple relatively minor issues).
However, it was only fairly recently that there has been a compiler and library that has implemented the standard apparently correctly.
This does not mean that when a compiler writer adds support for the hell that is 'export' he or she is extending the language. By contrast, the only thing they're extending is the amount of the language their tool implements.
I don't know what the OP was thinking, but I suspect it's along those lines.
(Granted, from the other posts it sounds like Mozilla is in fact extending the language.)
This entry in Asa Dotzler's blog contains links for downloading this release candidate of Deer Park Alpha 1.1.
The article has links to New Web Developer Features and New Extension Developer Features. There's also a page listing New Browser Features and an unofficial page listing Notable bug fixes.
The shareholder is always right.
Many of MSIE's extentions were put in there for "internal use" in standalone HTA applications and parts of the Windows UI.
Hell, I'm guilty of doing this myself. When my domain registrar asked for data they didn't need, all it took was typing a few characters in the location bar (javascript:...) to completely bypass their client-side input check and submit the incomplete form--which the server blindly accepted.
Web apps that don't do server-side input validation are simply the hallmark of an amateur.
The point is that Mozilla is simply adding a few new functions. They've also documented the functions and released them in such a way that copying them exactly woul take no real effort. Hell, you can add the same functionality to your pages, in a completely cross platform manner by including:
Array.prototype.forEach = function(fn) {
for(var i =0; i this.length; ++i) {
fn(this[i], i, this);
}
}
function foo(obj, index, array) {
alert("index " + index + " is " + obj);
}
[4,5,6].forEach(foo);
... in your javascript, for example. (thanks to neil.pearce)
These new functions, I would think, are for the writers of extentions and themes, not really for HTML authors. But, regardless, the changes are a far cry from MS's closed additions to Java that broke code written for Sun's standard JVM. These changes to Mozilla are more akin to a new header file included with GCC or such - where if you want to use the same thing with a different tool, just copy/paste.
Please ignore the Microsoft troll. (Yes, parent works for Microsoft -- click on the link to his webpage.)
On the contrary, the additions mentioned in this article are simply additional methods (a method in javascript is simply a property that contains a function).
For example, see the documentation for the new forEach() method :
http://developer-test.mozilla.org/en/docs/Core_Jav aScript_1.5_Reference:Objects:Array:forEach
The additions are not reserved words.