<script type="text/jquery">
ejohn.org
ejohn.org
In short it was an experiment to develop an alternative syntax to jQuery (I've always felt that jQuery's syntax and idioms are very much like a domain-specific language for traversing and manipulating the DOM). One of my primary reasons for creating jQuery was to develop a library that had very little syntactical overhead. This jQuery^2 experiment was trying to take it to the next extreme (almost no syntax, just some whitespace). To do this I built a very-hacky parser and search through the page for scripts that have a type of "text/jquery".
You'll note that the script that runs the page is actually in this meta-language. Also note that the code in the textarea compiles to some nonsense that doesn't actually run on that page. I was mostly just throwing in code to test the parser.
Projects like Cappuccino have taken this idea to the extreme and developed complete languages on top of JavaScript that are much more functional than what I present here.
Glad people are finding it to be interesting, though!
And I'd argue there's no reason not to want to optimize the syntax like this.
1. http://www.cincomsmalltalk.com/video/2008/sts/ometa_keynote_... 2. http://tinlizzie.org/ometa/
I found someone who had already done somthing similar using ometa. Here's a smalltalk syntax in javascript: http://tinlizzie.org/ometa/ometa-js-old/
Unfortunately I never practiced the stuff I learnt in 'language translators' at uni and have forgotten the details. This source may be useful, although I'd prefer it to work dynamically rather than having a compile stage. Other advice welcome.
If you're making it "work dynamically" then that's an interpreter and you can typically expect a 10x slowdown. I'd go the compilation route personnally.
Scheme2JS, ocamljs, haxe, and others all do inlining. The code size gets a little bit larger, but if you have actual performance problems in loops, it can be worth it. Minify-ing and zip usually make JS code sizes trivial anyway.
I think the way things are right now, it works just fine with one small exception: I got spoiled by jQuery. I do everything in it. I don't mean just web projects, I mean I do command line stuff with it. I have Firebug installed and so every time I end up on a website where I need to extract some information out of it, I fire up Firebug and do something along the lines of this:
(function(){ var x = document.createElement( 'script' ); x.src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min...; document.getElementsByTagName('head')[0].appendChild( x ) } )();
// Wait for jQuery to load...
jQuery('span.comhead').each(function(){ console.log( jQuery(this).text() ) });
It would really be ideal if Firebug shipped with jQuery built in, or at least have an option. This way I wouldn't have to do this every time I want to do some DOM-fu. Come to think of it, I should make this I should publish this bookmarklet.
jQuerify bookmarklet: http://www.learningjquery.com/2009/04/better-stronger-safer-...
The last thing we want to do is give browser vendors more control over any part of the process.
but it looks like nice cross of python and js
[edit] and running didn't do anything on chrome...
ps: they will never do asm the way we did :)