Slashdot Mirror


JavaScript Inventor Speaks Out

Anonymous Coward writes "Brendan, on his mozillazine blog talks about JavaScript 1, 2, and in between in light of DHTML and AJAX. In an informal blog entry he answers frequently asked questions such as fixing Unicode in regular expressions, multi-threading, weak numeric typing, and obfuscating code."

41 of 267 comments (clear)

  1. It Would Be Nice... by __aaclcg7560 · · Score: 2, Interesting

    If the "write once, run everywhere" feature was implemented. ;)

    On a related note, I had an interview at Adobe a while back and the interviewer mentioned that javascript was the scripting language for a lot of their products. I drew a blank on that one since I had no idea how use javascript for an application (and, subsequently, didn't get the job). When an application uses javascript for the scripting language, does that mean a javascript parser is also implemented into the application? Or can javascript be used in a standalone environment?

    1. Re:It Would Be Nice... by fm6 · · Score: 2, Interesting

      WORE is Java, not Javascript -- though I'm guessing you knew that. There's actually a platform-independent Java software out there. It's just that people have become too cynical about Java hype to care.

    2. Re:It Would Be Nice... by LetterJ · · Score: 2, Interesting

      PHP->COM->Photoshop is a bit of fun. At least for the few prototypes I've built for the fun of it (yes, that's the kind of sick freak I am).

      Most open source scripting languages can access COM objects on Windows. Once the syntax issues are out of the way, most of them work the same way.

    3. Re:It Would Be Nice... by dwlovell · · Score: 5, Informative

      Javascript is a scripting language that can be plugged into anything that has a script host for it. Dont confuse javascript with the DHTML DOM. Plenty of javascript code is perfectly valid and does not run inside a browser:

      - Windows Scripting Host allows you to write shell scripts in many languages (Javascript, Perl, VBScript) You can install new script engines and it will host those languages as well. WSH gives you a object model to access the disk and other windows components. (COM, ActiveX, etc).
      - Classic ASP used the Windows Script Host javascript engine so that js can be the language for ASP. (instead of the default of vbscript). Again, you could use any language that a script engine was installed for, including PERL. (see ActivePerl).
      - I also believe some cgi scripts can be written in javascript.

      Just because you aren't accessing the DHTML DOM objects (document, location, windows, etc) doesn't mean you aren't coding javascript!

      -David

    4. Re:It Would Be Nice... by prockcore · · Score: 3, Informative

      When an application uses javascript for the scripting language, does that mean a javascript parser is also implemented into the application? Or can javascript be used in a standalone environment?

      A javascript parser is included in the application. The opensource ultima online server UOX3 used SpiderMonkey (Mozilla's javascript engine) to handle server-side scripting.

      It's actually not that difficult to link spidermonkey into your application. I did it once for a benchmark program (it would pull a web page, and parse the javascript banners etc and time how long it took to download every piece of data required to render the page).

    5. Re:It Would Be Nice... by Pieroxy · · Score: 2, Insightful

      People are confusing the language and its more popular set of libraries.

      Javascript is a language

      The DHTML DOM (window, document, location, etc...) is merely an API. When you code in another environment, there is another API. For exemple, when ASP uses JScript (and not JavaScript, but it's pretty similar), APIs are such as ADODB, file system access, db access, etc...

  2. JavaScript by nepheles · · Score: 4, Interesting

    It's a pity JavaScript rarely gets the attention it deserves as a legitimate programming language. Most guides to C begin with teaching you how compilers work; most guides to JavaScript teach you how to swap some images.

    This is unfortunate as it's quite powerful: it supports first-class functions and an excellent generic object-system, not to mention the usual suspects such as dynamic memory management.

    Hopefully its apparent resurgence these days (as browser vendors get their compatibility acts together) will change this.

    --
    ((lambda x ((x))) (lambda x ((x))))
    1. Re:JavaScript by NutscrapeSucks · · Score: 2, Informative

      You can't run a javascript script from the command line. You can't click on an icon to run a javascript program

      I guess you haven't run Windows in quite a while, because all of this works as expected. (The console command is cscript myscript.js)

      --
      Whenever I hear the word 'Innovation', I reach for my pistol.
    2. Re:JavaScript by dtfinch · · Score: 3, Interesting

      I protect my javascript with stuff like this:

      // Copyright 2005 David Finch
      // Don't steal

      It seems to work. There must be a few people out there who still respect copyright.

      I even put a BSD license on one of my scripts, essentially making it public domain, and somebody asked for permission to copy it.

      shameless plug

    3. Re:JavaScript by dustmite · · Score: 2, Interesting

      Heh - interesting, I've had similar experiences. I've written a few (very) small OpenSource games - nothing major, nothing well-known. I've distributed them very clearly under either GPL, BSD or even 'public domain' licenses.

      Yet people seem to have always asked my permission before using the source for anything, however tiny and insignificant the use. Some guys also asked my permission once to do a fork.

      In the beginning it seemed quite weird to me, now I'm kinda used to it.

      So yes, people seem to generally respect copyrights.

    4. Re:JavaScript by randall_burns · · Score: 2, Informative

      You also have stuff like Rhino that makes Javascript a _compiled_ language. You also have a .NET Jscript compiler. So, Javascript _can_ be a compiled language.

  3. The difference between the language and... by LetterJ · · Score: 5, Informative

    The difference between the Javascript language and the browser objects themselves has become more and more clear to me as I've worked heavily with both more complex Javascript like AJAX (where you aren't spending much time directly interacting with browser objects, but rather staying "inside" Javascript), working with JScript.NET for commandline programs, JScript in WSH and HTA as well as Photoshop scripting.

    Many of the things that bother me about "Javascript" turn out to be problems with IE or Mozilla's objects and not the language itself. Don't get me wrong, things like the Javascript date objects still bug me, but I'm growing to like the language itself much more than I used to.

    If you've only ever used Javascript in a browser, you may not realize that much of what you're working with is really the browser's object model. All of the window., document., document.form, etc. interaction form.submit(), etc. are all browser object properties and methods.

    I noticed before posting some questions about scripting outside the browser. In those environments, you just get a different set of objects instead of document.form, you get objects for the filesystem or an active image, just like in any other programming language that uses objects from outside (COM objects, .NET assemblies etc.)

    1. Re:The difference between the language and... by LetterJ · · Score: 5, Informative

      It isn't only used in browsers. I used it all of the time for other things. Granted, most of my use is on Windows workstations (such is the life of a web development consultant in Fortune 500 companies) as that's what I spend most of my day on. However, there are other alternatives out there for other OS's as well.

      On Windows (if you have a workstation or server), however, you probably already have the WSH accessible containers and the cscript.exe and wscript.exe interpreters. Simply making a script.js file (remember you can't use any browser objects, so search for "Javascript WSH" to get some more info) and running "cscript.exe script.js" will run your script from the command prompt.

      Beyond that, you can build WSC (Windows Scripting Components) that are Windows COM DLL's written in scripting languages. HTA's (HTML Applications) are HTML files outside the browser container. Just rename an HTML file to .hta and double-click it. HTA's have gotten a bad rap as they're ofen used in virus attacks. However, so are EXE's. With power comes the potential of abuse. HTA's leave the local access restrictions behind which means your Javascript can access local files, etc. When combined with the WSH Shell object, you can run local executables to process whatever you like. I've done little scripted apps that are HTA's that collect data via a form, save the form data to a temp file, run a commandline processor (which dumps out a resulting file), read in the results and delete the temp files. What you end up with is something like the current AJAX rage without a web server and acting like a local app, all while still using Javascript/HTML.

      If you're looking for more "real" applications, JScript is a full-fledged, if not well documented, language for .NET. You can compile to DLL's and EXE's directly and they are exactly the same resulting output as if they'd been written in C# or VB.NET. JScript.NET does bring some restrictions you may not be used to, including enforcing variable declarations, etc. However, it still retains a looser backward compatibility mode, resulting in many WSH scripts compiling as-is. All the tools for working with JScript.NET are free. The .NET SDK is free and contains all of the compilers. You do NOT need VisualStudio.NET to work with .NET languages.

    2. Re:The difference between the language and... by Hao+Wu · · Score: 2, Funny
      What do you mean by "realize" and "related" and "right"?

      I know that today is wednesday.

      --
      I suggest you read Slashdot
    3. Re:The difference between the language and... by Da+VinMan · · Score: 4, Interesting

      If that's your "secret" then you need to get out more. :+) Seriously, give Ruby a try. I think it will quite easily scratch the itch you're expressing. It has none of the confusion surrounding it that JavaScript does and it's quite a worthy desktop application and web application language. Oh, and if you're going to give Ruby a try and aren't totally addicted to Emacs or vim at this point, then give the Arachno IDE for Ruby (at http://www.ruby-ide.com/) a spin. It's not free, but it is cheap.

      FYI - Learning Java can also be worth your time; it's not so bad. But really, if you're going to have your application execute on the client in a browser, then Java really isn't a good choice these days. (Although I'm sure some would beg to differ; it is *possible* after all. I just don't recommend it.)

      Have fun!

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
  4. Re:Just what I wanted! by Mr.+Cancelled · · Score: 4, Funny

    I'd rather use a browser configured to show me the world wide web as a bunch of hypertext documents, not as a bloated adware-infested and spyware-infested application that moves crap around inside the browser window and pops up windows.

    Yes, but this is a discussion about JavaScript, not Flash.

  5. And why not? by Saeed+al-Sahaf · · Score: 5, Insightful
    but this stinks of DRM type shit. somewhat like that amazon fiasco that prevents the same user from viewing all the pages of a book.

    Honestly. Why should you be able to? Amazon SELLS books. It's not an on-line library. That's not the service they are offering.

    --
    "Who are in control, they are not in control of anything - they don't even control themselves!" - Glen Beck
  6. JS is very functional by Anonymous Coward · · Score: 5, Informative

    Try this site to see what I mean.
    http://www.masswerk.at/jsuix/

    1. Re:JS is very functional by CTho9305 · · Score: 4, Interesting

      Especially when combined with XUL.

    2. Re:JS is very functional by bcrowell · · Score: 3, Funny

      MOD PARENT UP!!!
      That has got to be the coolest thing since the invention of French kissing!

    3. Re:JS is very functional by Anonymous Coward · · Score: 2, Informative

      I agree. Check out these cool card games.

    4. Re:JS is very functional by nacturation · · Score: 3, Insightful

      All I know is that [javascript] has pissed me off more than any other "top 5" languages in the work place.

      And how many other languages do you use to write client-side code for web browsers? The problem is that the browsers don't all implement the same standards for their internal object models... but this is a result of using JavaScript to implement differing browser APIs, not a failure in JS itself. It's like saying that ANSI C is lousy because the same code for a graphical app will create errors if you compile it under Windows, Linux, and Mac. The language is fine it's just that those platforms, much like the browsers, implement different graphics APIs.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
  7. Javascript doesn't suck by stevens · · Score: 5, Interesting

    As someone who'd only used Javascript in creating DHTML, I'd worked up a good hate against it. But what I'd hated was really the ridiculously incompatible implementations of the DOM in IE/Netscape. I also hated the embedded space itself--shitty delivery method (encoded or called from HTML, no #include, no namespaces).

    Then I started writing extensions for firefox. I'm trying to show my company that (firefox + xul + js) > (ie + activex). I'm mostly successful, since we already have lots of XML over HTTP data services primed for XmlHttpRequest.

    But it turns out that the language doesn't suck so bad. Sure the namespace problem is JS's fault, but the rest is the embedding. Using JS for firefox exntensions allows you to code to one platform; make more OO libraries, etc. I even generate classes from the DTDs I make the XML services from.

    Who would've thunk it's really a decent language in the dynamic, lambda-toting, functional-ish area?

    1. Re:Javascript doesn't suck by stevens · · Score: 5, Informative
      I just wish that FF would let us going document.element instead of force us to write document.getElementById("element") in order to reference DOM objects. the former is less typing than the latter...

      That's not a feature, it's a bug. It's not FF, it's the w3c. And it's the right decision. Standards and all that, right?

      The document object already has a shitload of properties, and this IE idea doesn't cooperate nicely, since the property namespace clobbers the id namespace. Bad browser-maker! No cookie!

    2. Re:Javascript doesn't suck by stevens · · Score: 2, Informative
      I just wish that FF would let us going document.element instead of force us to write document.getElementById("element")

      Thinking more about it, what you may want is an implementation of E4X, which looks cool. I think it's going into newer mozilla-based browsers soon.

      It lets you address a parsed XML file in XPath-ish terms, like rootelement.child.text and such.

  8. Re:obfuscated code as a feature?!?! by Eberlin · · Score: 3, Insightful

    Code obfuscation isn't really a "feature" per se. I think the main problem is what you've mentioned -- that a lot of folks don't believe in the "Open Source" philosophy and yet use such scripting languages that by their very nature, are "open source." (PERL rants aside)

    It's writing code and hoping nobody else can understand, modify, improve, or possibly circumvent it. To be perfectly honest, I don't think code should be more obfuscated than it already is. The simpler and easier to understand, the better.

    I did run into a vbscript worm once that did something like rotX itself when transporting (with a random shift, I believe, to try to avoid AV fingerprinting), then decode and execute upon launch. I must say that was pretty neat in a sick sort of way.

  9. Re:JavaSuck? by Jedbro · · Score: 2, Informative

    Maybe because we actually know what we are talking about.

    Brendan Eich worked at Netscape back when the web was pioneered.. he created Javascript while there, and wrote the entire javascript engine for the Netscape browser (version 2 or 3, can't remember).. facts are facts.. I'm sure theres more info at wikipedia.

  10. Re:JavaScript Vrs. TCL by fm6 · · Score: 3, Interesting

    I think by the time Javascript came along, Sun had pretty much lost interest in TCL. I heard stories about people trying to license the Sun implementation of Tcl/Tk and getting a runaround. It's probably not a coincidence that Ousterhout left Sun (and took Tcl with him) at about the same time as Eric Schmidt, who brought Ousterhout on board in the first place.

  11. They have. by NoMoreNicksLeft · · Score: 2, Informative

    It's ECMAscript. Name hasn't caught on yet. ECMA = European Computer Manufacturer's Association, I do believe. Mozilla used to have some bugs where you couldn't use that as the attribute value for a "script" element. Or maybe that was with SVG.

  12. Re:I need to agree with fellow Slashdot participan by NoMoreNicksLeft · · Score: 4, Informative

    It's also responsible for Google Maps. That's the only big one that jumps out at me, but there are a few other uses I've seen, that I've liked. Try out greasemonkey, and make javascript work for you.

  13. Re:Just what I wanted! by dwlovell · · Score: 5, Insightful

    I mostly agree, but we do need Javascript. If you look at the Strict XHTML spec, there is no target="" attribute allowed on anchor tags. So if you want to open a link in a new browser, the official way to do it requires client-script (something about targetting is a browser behavior not a document structure semantic, so it should be script, not html):

    <a href="http://www.slashdot.org" onclick="window.open(this.href,'_blank');return false;">Slashdot</a>

    So you can argue that XHTML blows, or that you shouldn't open links in a new window, but if you decide you want to be standards compliant, you are going to need some client script. This is not the only example.

    -David

  14. Re:Just what I wanted! by Anonymous Coward · · Score: 3, Insightful

    No web page should ever open up a new browser window when the user clicks on a link. That's rude! The world wide web is a set of documents, not an application. Web pages should not be making decisions of that sort for the user.

  15. Re:I need to agree with fellow Slashdot participan by StikyPad · · Score: 2, Informative

    As well as GMail, the new Google Custom Frontpage (You know you can drag those boxes around?), and hmm.. well, just disable JS in your browser and see how many websites still function. It's ubiquity is why popups exist, as the GP pointed out, but the reason popup blocking software exists is because simply turning off JS would "break the internet," in the eyes of most users.

  16. Re:Just what I wanted! by nxtw · · Score: 2, Insightful

    Blah blah blah. There are situations where that's actually the most user-friendly thing to do, like when you're editing or entering information and need to display detailed instructions without losing the form, along with some other situations.

  17. Re:Just what I wanted! by Paua+Fritter · · Score: 3, Insightful
    There are situations where [opening a new window is] actually the most user-friendly thing to do, like when you're editing or entering information and need to display detailed instructions without losing the form

    You can do this with CSS, and without having to call back to the server for the "help" content as another web page

    Define your help notes as divs which are hidden (display:none). Then you have your "help" hyperlinks point to those divs, which can then become visible (because they have the focus a different CSS rule applies and they can get display:block or whatever).

    Opening new windows is almost always a bad idea. "User-friendly" depends not just on the technique but also on the user. For some people it may work, in some circumstances, but for other people (people with visual impairments, for instance) it is never friendly.

  18. Re:Just what I wanted! by Anonymous Coward · · Score: 3, Informative

    You can be standards compliant and still use target with XHTML strict. One of the bigs things about XHTML is that it is modularized and target was just moved to a module which you can import in your documents:
    http://www.w3.org/TR/xhtml-modularization/DTD/xhtm l-target-1.mod

    Using JavaScript for this, which people can disable or just selectively cripple, is a terrible idea and you start getting all these non-standard handlers spread around.

  19. Re:obfuscated code as a feature?!?! by Tim+C · · Score: 2, Insightful

    somewhat like that amazon fiasco that prevents the same user from viewing all the pages of a book.

    If Amazon didn't at least attempt to prevent you from accessing every page of each book, they'd be unable to offer the service at all as there's no way the publishers would agree to it. They'd essentially be providing a mechanism to get the text of the book for free.

    If enough people piss about with it, Amazon *will* be forced to either withdraw the service, or just put up (say) five pages of each book and leave it at that, which would greatly reduce its usefulness.

  20. JS rocks by famebait · · Score: 3, Insightful

    It never ceases to amaze me how people can do sometimes extensive work with JavaScript and still not spot what an elegant and powerful language it is. Sure, most of that work is about doing meaningless browser-related stuff and wrestling with bad APIs, but come on. I really do expect from an averagely talented real IT person to be able to separate that from the langauge, and be able to recognise the things it can do that their normal language can't. Its almost single-abstraction design that turns out to be able to do just about everything and still look nice and procedural and newbie-friendly totally rocks.

    --
    sudo ergo sum
  21. Relief at last! by Qbertino · · Score: 4, Insightful

    Finally somebody who isn't a total dickhead speaks up on the Ajax craze.

    "With DHTML and AJAX hot (or hot again; we've been here before, and I don't like either acronym) ..."

    Bingo!
    The man's right on.

    --
    We suffer more in our imagination than in reality. - Seneca
  22. Re:Is it just me... by The+Cookie+Monster · · Score: 2, Informative

    Removing all unneccesary whitespace and replacing var and function names with 1 or 2 letter replacements is also a means of compression.

    Open source languages are not designed to only be used on open source projects, restricting what it can be used for goes against the whole point.

    Besides, nobody has a problem with GCC producing output without embedded data to make it reversable.

  23. Don't evolve; stay a *standard* by mactari · · Score: 2, Interesting

    I'm sorry, but this comment simply doesn't hold:

    JS is not going away, so it ought to evolve. As with sharks (and relationships, see Annie Hall), a programming language is either moving forward, or it's dead.

    No, when a programming language doesn't chance, it's called a standard. Look at what we've been able to do keeping html, css, and javascript a stable target for so many years! It's like Space Invaders on the Atari 2600 -- nobody who created that console, its hardware designed specifically for playing Combat and Video Olympics, expected someone to be able to slap six sprites in a row, much less have the player shoot then down one at a time. The 'standard' that was the 2600, however, gave a stable platform for programmers to learn tricks that would give the console life well beyond its creators' expectations.

    We've got something like that with javascript, and we can see what happens when we compare to something like Visual Basic 6. Developers are still upset about Microsoft's decision to drop official support for VB6 in an attempt to force people to upgrade to VB.NET. Know what? Those upset programmers have found that VB6 hasn't rusted and simply continue using it to create their apps. There are more companies than you'd know (here's one) whose major apps are/were written in VB6, the 'prototyping language'. They're not quite ready to cast the baby out with the bath.

    Fix bigs in javascript? Absolutely. The issue is that we've reached a point where nearly every browser anyone uses supports a 'single' flavor of javascript and we're all familiar with how to make our code work with the few quirks that remain crossplatform. There is a standard on nearly every box on the net that coders can assume will be there for them. I wouldn't want to see anyone mess this stable delivery platform up, splitting the user base into something like what we had in the Netscape 4.x/Mozilla/IE 4 & 5 days. Now *that* was an ugly time to code.

    The bottom line is that evolution is an overused metaphor. You've got two choices if you'd like to propagate your genes into the future: immortality or reproduction. Immortality was a little too difficult to accomplish for living, unique individuals. Perhaps there were little organisms that could live forever, but something squashed 'em. They're gone. That's not a problem in the digital world, folk. We can make as many exact copies of an individual as we'd like. Javascript modules are not unique. They don't need to evolve. (I mean, come on, he even mentions sharks, a design that hasn't changed in millions on millions of years!)

    Javascript should shoot to become an immortal standard, not another field of play and debate.

    --

    It's all 0s and 1s. Or it's not.