Forgot your password?
typodupeerror
Mozilla The Internet

Mozilla Extending Javascript? 286

Posted by Zonk
from the busy-little-devs dept.
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?"
This discussion has been archived. No new comments can be posted.

Mozilla Extending Javascript?

Comments Filter:
  • by TheSpoom (715771) * <slashdot@uberm00. n e t> on Saturday May 28, 2005 @04:40PM (#12665707) Homepage Journal
    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.
    • by 1010011010 (53039) on Saturday May 28, 2005 @04:46PM (#12665750) Homepage
      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.
      • > They can't be used in web pages unless you want them to be Mozilla-only, of course.

        Of course, who wouldn't want their web page to be Mozilla-only? I think I am going to rewrite my webpage with these extenstions in mind. Fuck off and die, IE.
        • Except, why would you want to exclude Opera or Konqurer or Safari?
    • by eyeye (653962) on Saturday May 28, 2005 @04:47PM (#12665755) Homepage Journal
      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.
    • by vidarlo (134906)
      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.)

      This mainly depends whatever any other browser picks it up. Compare this with last stor

      • by neil.pearce (53830) on Saturday May 28, 2005 @06:00PM (#12666196) Homepage
        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.
      • E4X is a standard [ecma-international.org] published by the same group that publishes the ECMAscript standard. I don't think the array extras are described by any standard.
    • Right, nearly all time spent coding in Javascript is spent making sure it works correctly in different browsers.
      Unfortunately, it will be a cold day in hell when IE has decent support for the standards -- and add an aeon or two until older versions of IE are phased out.

      This said, I'm not a web developer myself -- but when I updated our company's website recently, I would have spent around 10% of the time I needed. Coding around all quirks in different browsers is NOT FUN.
      • by DrSkwid (118965)
        if you did spend all day working in ajavscript, then you'd know that you can create a standard library that will work cross browser

        one can replace any functions that are missing or don't work how you like them.

        I remember back in the days before getElementById in I.E. I added my own so that I could write my code assuming it was present :

        document.getElementById = function (id) { ..... }

        as you go along you find out what works what doesn't.

        It's not *that* different from developing wxWindows or gtk to work
      • To be fair, your problems are nothing to do with Javascript. It is the differences in the DOM provided by each browser that is giving you strife.

        Mozilla, Opera and Internet Explorer all implement Javascript remarkably well.

        (As a C/C++ developer) would you call differences/bugs in some "commonly expected to be present" 3rd party library a problem with the C/C++ language?
    • by neil.pearce (53830) on Saturday May 28, 2005 @05:43PM (#12666071) Homepage
      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)
  • What? (Score:3, Insightful)

    by Umbral Blot (737704) on Saturday May 28, 2005 @04:42PM (#12665718) Homepage
    Ok I understand there are several benefits to this for extension writers. However, I seriously doubt that it will be used in many other places. After all who wants to write web pages that won't work properly in IE and Safari?
    • Re:What? (Score:2, Interesting)

      by Anonymous Coward
      Right now I'm doing some Web development work within my company where I can control all of the specs. I KNOW what computers, what browsers, &c. will be using the application and if these extensions were to prove useful, I'd just use them. The plan all along was to standardize on Mozilla for this, so that's not really a problem.

      Would I use this for a site that outsiders would ever access? No.
    • by mcc (14761)
      Ok I understand there are several benefits to this for extension writers. However, I seriously doubt that it will be used in many other places.

      Does it need to be used in any other places to have been worthwhile, from the Moz people's perspective?
  • Moz Extensions (Score:5, Interesting)

    by multipartmixed (163409) on Saturday May 28, 2005 @04:42PM (#12665720) Homepage
    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.
    • I think we're going to see some of the same things added to IE7's Javascript engine, but implemented differently.

      Which means more special-case code for web developers.
      • IAAWD

        The question springs to mind...

        "Why?"

        One of the big features MS are pimping for IE 7 is standards compliance - I'd be surprised if everything works perfectly, and they'll still be all the other versions to deal with, but I really don't see why they'd delibrately run in and implement what is essentially a few simple methods, and an implementation of a W3C spec.

        I have to say, I'm more interested in implementation of some CSS3 attributes, and the <canvas> tag.
    • you must be kidding yourself. MS added functionality to do what, not for developers to use them. Extending a standard aka EMCAScript, IS extending it, they are doing exactly what MS and Netscape did back in the day.

      But I do not mind that because otherwise we would not have font, css and many of the other things people take for granted in html.
  • ... and not something that the Mozilla guys could futz around with on a whim.

    Mind you, we are talking about the people who brought you the BLINK tag.
    • by slavemowgli (585321) on Saturday May 28, 2005 @05:06PM (#12665873) Homepage
      Most, if not all, Mozilla extensions use Javascript, so that's most likely what these changes are aimed at. I don't think you're supposed to use them on public webpages; if the Mozilla guys really care, then they'll also make sure that these extensions won't work in that case.
      • Most, if not all, Mozilla extensions use Javascript, so that's most likely what these changes are aimed at. I don't think you're supposed to use them on public webpages; if the Mozilla guys really care, then they'll also make sure that these extensions won't work in that case.

        Funny... that exact same argument didn't work for Microsoft with their extensions to Java... why should we let Mozilla get away with it?
        • Funny... that exact same argument didn't work for Microsoft with their extensions to Java... why should we let Mozilla get away with it?

          If you don't want to use the new functions, don't. A bit of javascript that renders in IE doesn't magically not work in Mozilla because of these new functions. Effectively, they're adding a few new functions to their standard implementation - they're not changing the way pre-existing functions work (like MS did with Java).

    • 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 [mozilla.org]. 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 s
    • They're not futzing around with ECMAScript; they're implementing parts of ECMA-357.

      This specification has been around since June 2004, look it up on http://www.ecma-international.org/ [ecma-international.org]
  • Dark Peer? (Score:2, Funny)

    by tunabomber (259585)
    My dyslexic eyes first read "Mozilla's Deer Park" as "Mozilla's Dark Peer". I was pretty disappointed when I corrected myself. Having a P2P darknet with a XUL frontend would be pretty badass, after all.

    Oh well, time to RTFA.
  • by Anonymous Coward on Saturday May 28, 2005 @04:45PM (#12665743)
    They're not extending javascript from what I can see. It looks like they're implementing some features that weren't implemented before.
    • by rbarreira (836272) on Saturday May 28, 2005 @05:08PM (#12665895) Homepage
      Yeah. In other news, I don't want to shoot you, I just want to fire a gun at you...
      • By the way:

        JavaScript 1.5 (Gecko 1.8b2 and later): added every, filter, forEach, indexOf, lastIndexOf, some, and map methods (not part of ECMA spec)
      • Yeah. In other news, I don't want to shoot you, I just want to fire a gun at you...

        This is veering off topic, but what the heck.

        <Stewey from Family Guy>

        "It's not that I want to kill her... I just want her not to be alive anymore.

        </Stewey from Family Guy>
      • by Stauf (85247)

        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

  • Kettle meets Pot (Score:4, Insightful)

    by Neopoleon (874543) on Saturday May 28, 2005 @04:47PM (#12665756) Homepage
    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...
    • Do you really not see the difference?

      You'd really have to be completely stupid to use JavaScript in a web page that only works in one browser, even if that browser has a 90% market share. You'd have to even more stupid to use JavaScript in a web page that only works in a browser with less than 10% market share.

      I really don't think these "extensions" are intended to be used in web pages. I'm also pretty dubious of your (unintended?) implication that the folks at Mozilla are doing things to lure deve

  • I view these developments as steps on the road of Mozilla 2.0 It makes sense that a new major version of the open source browser includes innovations just like what Netscape did for their Navigator.
  • Maybe this time they'll actually not think that two digit years are automaticaly in the 20th Century.

    Or, heaven forbid, they'll actually use the actual standards based (and *GASP* Microsoft sponsored) ECMAScript as a base which had already fixed their embarassingly humerous (for a 1995 language) Y2K bug...
    • Oh, and just to be precise, if they use a corrected base, perhaps it should be labeled that they're extending ECMAScript or ECMA Standard 262 Scripting Language or JScript since the name JavaScript was just a silly attempt for Netscape to try to glom on to SUN's Java PR machine by renaming their LiveScript language despite Java and JavaScript having nothing in common except being C derivatives written by companies that hated Microsoft.
  • Great more exstentions, more media I want to block, ugh... 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, I love Opera, and it is my browser of choice but I still have to deal with unwanted flash animations. I am stuck on 26.4 bps dialup, due to bad phone lines, and lack of avaliability for cable/dsl/direct wireless. I do not want or need to see more bloat in webpages.
    Ok, I am whining again, but you would whine too if you had
    • If you're on Windows, I'd strongly recommend Proxomitron [proxomitron.info] - 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 [mozdev.org] (although that's possibly overkill).
    • by Phroggy (441) * <slashdot3&phroggy,com> on Saturday May 28, 2005 @05:12PM (#12665913) Homepage
      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 [mozdev.org]. Or if you really never want to see Flash animations, you could always uninstall the Flash plugin...
    • Back in the dark ages I used to surf primarily with Links since even images at that speed are unbearable.

      Satelite internet could be an alternative but that's only marginally better if you're expecting the responsiveness and throughput of DSL/Cable etc. Typical satellite instalations are latent anywhere between 800ms~1200ms. I've seen a couple under 600ms regularly but these were rare. Not to mention 500kbps is about as high as you can get with it.

      Direcway [direcway.com] have been at it for a while, Starband [starband.com] Provides
  • by Anonymous Coward on Saturday May 28, 2005 @04:51PM (#12665788)
    Deviance from standards (at least in a web environement) is bad because the code that works in one browser won't work in another browser.

    But that's not necessarly a bad think in my opinion. If one browser starts extending and empowering web developper in many and novel ways, this browser may well raise the bar for all browsers and shit expectation (if developper find, in mass, that the features are worthwhile, cool, useful, etc...).

    However, deviance from standards are bad if they are unsignificant, unrevolutionary, unimportant, just a little improvement (not to confound with many little improvments that combined can make a big difference).

    So if you're going to deviate from standard, do it big time!
  • The best part.. (Score:4, Interesting)

    by Eloquence (144160) on Saturday May 28, 2005 @04:52PM (#12665790) Homepage
    ..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 [wikimedia.org], 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.

    • Re:The best part.. (Score:3, Informative)

      by BRock97 (17460)
      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 believ
  • Array methods (Score:4, Insightful)

    by Zontar The Mindless (9002) * <plasticfish@info.gmail@com> on Saturday May 28, 2005 @05:00PM (#12665844)
    Many of the new Array methods are similar to methods I've written myself and used for years. Admittedly the methods themselves aren't part of the ECMA spec, but object extension via prototyping is a core feature of the language. It shouldn't be difficult to implement them on your own for other browsers.

    They'll just run a bit faster in Mozilla/FireFox, is all, since they'll be run as part of the interpreter rather than as interpreted code.

    Most of the other stuff is based on W3C standards.

    Short version: I'll continue to do cool stuff quickly in Moz and spend time writing workarounds for MSIE, just like I've been doing for the last 4-5 years. Nothing particularly new about that.
  • by Nom du Keyboard (633989) on Saturday May 28, 2005 @05:10PM (#12665903)
    What the world needs here is a JS plug-in that works with all major browsers (or a version for each) so that there really is a compatible language across them.

    World Peace would be nice too.

  • I got pretty excited when I read about some of the new JS improvements. Mostly about the new drawing-capabilities. All the details here [slashdot.org].

    Is is basically a direct-mode graphics canvas, as specified by WhatWG canvas specification [whatwg.org], which allows you to draw all kinds of graphic primitives using Javascript. This is based on Apple's implemented in Safari.

    I would hope that some highly innovative graphics-applications can become possible using Javascript, when this goes mainstream.

  • by Anonymous Coward
    Mozilla Extending Javascript = yes (read the posting)
    Are web designers going to use it = no since they like "write once, run everywhere"
    Will extension developers use it = yes
    Will anybody remember the person responsible for Javascript in the first place?
    Well, see for yourself, a document that he maintains Roadmap [mozilla.org]
  • I wish they'd extend it by replacing it with python.
    • How about "making Python available as an alternative to Javascript" instead? I could go for that. You'd probably have to tweak on the interpreter so that it's restricted to interacting with stuff inside the browser environment. I've embedded Python in other applications, and it generally isn't that hard to do, as long as you aren't worried about giving people complete freedom inside the scripting environment.

      I wonder how much trouble it would be to embed a restricted Python in Mozilla...I should probabl
  • by MarkEst1973 (769601) on Saturday May 28, 2005 @05:33PM (#12666012)
    Using Rhino http://www.mozilla.org/rhino [mozilla.org] -- which already has the E4X functionality in the runtime -- you can stuff like this (using an html document as my sample xml):

    var html = <hmtl/>
    html.head.title = "my title";

    print(html);

    This prints as:

    <html>
    <head>
    <title>my title<title>
    <head>
    <html>

    Although this is a contrived example, I find the ability to access XML as native objects using dot-notation to be very convenient and useful.

  • ...but no inline-block. At least, not according to this page [mozilla.org]. :(
  • More links (Score:4, Informative)

    by jesser (77961) on Saturday May 28, 2005 @06:05PM (#12666226) Homepage Journal
    This entry in Asa Dotzler's blog [mozillazine.org] contains links for downloading this release candidate of Deer Park Alpha 1.1.

    The article has links to New Web Developer Features [mozilla.org] and New Extension Developer Features [mozilla.org]. There's also a page listing New Browser Features [mozilla.org] and an unofficial page listing Notable bug fixes [squarefree.com].
  • I wish that Mozilla would only allow these language extensions (such as the -moz CSS properties) to work in Mozilla extensions. These are obviously useful language tools, but the web is divided enough as it is. This way, the browser extension development scene could serve as a test bed to language extensions. The new syntax and functions don't seem to have been widely tested. If somebody finds a problem with the initial release, will the next version of Mozilla have a new syntax? These extensions should b
  • Mozilla and Cairo (Score:3, Interesting)

    by krappie (172561) on Saturday May 28, 2005 @06:32PM (#12666366)
    I think what deserves more attention is the badass development of cairo [cairographics.org] into Mozilla.

    Check out the blog of the main developer thats doing this development. Hes got some excellent demo screenshots.
    http://weblogs.mozillazine.org/roc/ [mozillazine.org]
  • Do folks normally browse with javascript activated?

    I usually do not, since I don't want silly animations chewing up cycles, or annoying floating thingees obscuring content.

    Sure, it's annoying to have to click through menus to turn javascript or java back on for those few pages where I need it, but that's less annoying than having it turned on by default.

  • by wiresquire (457486) on Saturday May 28, 2005 @07:13PM (#12666584) Journal
    IMHO, the big trap, particularly for newbies to javascript is using features/functions that are not part of the standard without knowing it.

    ie it should be very recognisable that you are using something that is not part of the ECMA standard.

    In Java land, that's made somewhat obvious by the import statement - the namespace for standard is java/javax, and, eg com.* or org.* etc are for everything else.

    Actually the same should be the case for HTML etc.It should be obvious when there are tags/features being used outside of the standard just by looking.

    The best way to let people code to standards is making it easy as hell to tell what is standard or not - without reading a gazillion pages of specs that they may not even understand.

    ws
  • Standards? (Score:3, Interesting)

    by shancock (89482) * on Saturday May 28, 2005 @07:21PM (#12666626)
    I guess I don't get it. If one is only developing for a private intranet and will not be accessed by any other browsers except Mozilla, then this is basically creating propriatary software where anything goes anyway. Otherwise it seems to be similar to the old Netscape/MS IE extensions war for browsers that caused so many problems years ago ( and still is causing problems).

    What happens if the company wants to scale up later to allow clients to view or to incorporate this great new stuff on the/a public website. It just doesn't make much sense to me in the long run.

    Am I missing something important here?

  • Deer Park (Score:2, Insightful)

    by NightFears (869799)
    Damn, doesn't it sound familiar to embrace-and-ex...

    Well, let's see. Netscape invented JavaScript, Microsoft did its best to break it. But, not without the help from the Mozilla Foundation, the proprietary plot has been demolished and by now everyone, except the most lazy and ignorant, seems to know that you can't trust Microsoft's innovations to lead you to the light.

    But isn't it about the time to make another step forward? And who would YOU choose to bring you there? As for me - I, for one, welcome our
  • I've found this interesting since some sites use images as cursors for IE, and that would be a welcome improvement to Firefox also:

    URI values on CSS cursor properties
    On Windows, OS/2 and Linux (Gtk+ 2.x) one can now use an arbitrary image as the mouse cursor while a given DOM node is being hovered. Any image format supported by Gecko can be used for the image (SVG, animated GIF, and ANI cursors are not supported).

  • or sleep(), delay() or whatever they want to call it, window.setInterval() is a big ol POS on a project I'm working on because I can't maintain state with it.

UNIX is many things to many people, but it's never been everything to anybody.

Working...