Slashdot Mirror


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?"

14 of 286 comments (clear)

  1. Javascript Extensions by TheSpoom · · Score: 5, Insightful

    I don't think the Javascript extensions will be used very much. Personally, I'm coding Javascript that will work in most browsers, which means I have to specifically exclude this new Javascript unless IE et al also implement it (and even then, older browsers still won't like it). Not to be anti-Mozilla, but this does sound a bit like embrace and extend to me. (Yes, I know it's open source and others can read the specs.)

    On the other hand, it looks like the things that they did add were mostly based on standards and the DOM spec, so we'll see where this goes.

    --
    It's better to vote for what you want and not get it than to vote for what you don't want and get it.
    - E. Debs
    1. Re:Javascript Extensions by 1010011010 · · Score: 4, Informative

      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.
    2. Re:Javascript Extensions by eyeye · · Score: 5, Insightful

      As a XUL developer I welcome these additions that will make the language more pleasant to code in.

      They shouldnt be used where they impact on cross browser compatibility though.

      --
      Bush and Blair ate my sig!
    3. Re:Javascript Extensions by neil.pearce · · Score: 4, Informative

      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)

    4. Re:Javascript Extensions by neil.pearce · · Score: 4, Informative

      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);

    5. Re:Javascript Extensions by neil.pearce · · Score: 4, Informative

      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.

    6. Re:Javascript Extensions by mjh · · Score: 4, Funny
      As a XUL developer I welcome...

      Was it just me or did anyone else finish that sentence with, "our javascript overlords" or some other such permutation?

      I might watch too much of The Simpsons.

      --
      Key to financial independence: Spend less than you earn. Save and invest the difference. Do it for a long time.
  2. Moz Extensions by multipartmixed · · Score: 4, Interesting

    This isn't a case of 'embrace and extend', microsoft-style -- this is a case of extra functionality needed to write extensions. Any web developer using these for public apps is clearly a butt-head.

    --

    Do daemons dream of electric sleep()?
  3. Article badly termed? by Anonymous Coward · · Score: 5, Interesting

    They're not extending javascript from what I can see. It looks like they're implementing some features that weren't implemented before.

    1. Re:Article badly termed? by rbarreira · · Score: 4, Funny

      Yeah. In other news, I don't want to shoot you, I just want to fire a gun at you...

      --

      The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
  4. Kettle meets Pot by Neopoleon · · Score: 4, Insightful

    Great.

    So, people used to get pissed off about Microsoft playing around with scripting features in IE that weren't available on other platforms, but now it's going to be an *advantage* for Mozilla?

    Hello-o-oo-oooo-o-ooooo...

    --
    - Rory [Microsoft Employee] | Free dirt: neopoleon.com
  5. Re:Firefox "stuck" at 10% market share by Tatarize · · Score: 5, Funny

    I agree, lets bundle it with Linux.

    Hmm..

    --

    It is no longer uncommon to be uncommon.
  6. The best part.. by Eloquence · · Score: 4, Interesting
    ..is the super fast back/forward cache (add a new positive Integer value browser.sessionhistory.max_viewers in about:config to enable it). My impression is that it's even faster than Opera's, though there seem to be some conditions under which a slower reload is used. In any case, this is an absolute killer feature, and I hope they manage to get it ready to be enabled by default for 1.1.

    The other killer feature is, of course, SVG support by default -- unlike the crappy Adobe plugin, fast and reliable SVG support. A lot of stuff that is currently done in Flash can be done in SVG without any dependency on non-free software (or unstable, experimental open source players). Personally, I'm most excited about its possible uses in Wikipedia. Unlike a bitmap file, an SVG can be collaboratively edited: translate text, fix mistakes, and so on. Beyond illustrations, SVG is also useful for zoomable timelines, of which Wikipedia has quite a few, and which are already exported as SVG.

    I think that Firefox support for SVG could be a major reason to switch from other browsers if we come up with cool SVG-based applications (not that we really need more reasons to switch!). One thing that would be neat is the ability to generally pan and zoom an SVG file even if there are no JavaScript controls for that, I haven't seen that functionality. Perhaps a bookmarklet or GreaseMonkey script could do the trick.

    I can't wait for the final version, but I'd be happy to wait 3 months longer if that's how long it takes to get it ready for primetime. One thing is for sure: Firefox 1.1 will kick butt.

  7. Re:what about the few of us stuck in no-mans land? by Phroggy · · Score: 4, Insightful

    Great more exstentions, more media I want to block, ugh...

    I don't think you have any idea what you're talking about. These extensions to JavaScript will make the language easier to program in, which will be nice for the parts of Mozilla that are written in JavaScript (quite a bit, actually) and for things like Firefox extensions. It doesn't sound like they'll provide any undesirable functionality - we're not talking about floating popup windows here.

    Why can't anyone write something to block all of this stuff out, I don't want to see graphics, or animations, or hear sounds,

    That's precisely what several Firefox extensions do, and these additions to JavaScript will make extensions like that easier to write and maintain (and probably faster to use and smaller to download).

    I love Opera, and it is my browser of choice but I still have to deal with unwanted flash animations.

    Well, maybe you should switch to Firefox with the FlashBlock extension. Or if you really never want to see Flash animations, you could always uninstall the Flash plugin...

    --
    $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
    $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;