JABBASCRIPT
VEENA WANNA WONGA SOLO!
Jabbascript is the result of being presented with the question (not but 12 hours ago!) what I would change about JavaScript -- at the language level -- if I could.
Well, it turns out, I really don't want to change that much. I've tried CoffeeScript; it left me with a syntactic sugar headache. Maybe I can't help myself: I just really like JavaScript the way it is!
That said, I recently saw @jashkenas propose a simple class syntax that desugars nicely to ES3/5. I've loosely adapted it here, along with three other changes.
THE CLASS SYNTAX
class [NAME] [extends EXPR] EXPR
returns a Function
// the new class syntax: var X = class { thisx = x thisy = y } // desugars to: var { ifthisinit thisinit} Xprototype { thisx = x thisy = y} // named classes: // `init` is the magic constructor. { return "GLADLY" } // and linking prototypes: // to function constructors... { // superclass methods are available on `superclass`. return MyListsuperclassmap } // and objects. extends a:1 a:2
THE BINARY TIGHT-BINDING LOOKUP OPERATOR
[NAME | DOT | LOOKUP] : [NAME]
attempts to return a function bound to the LHS from an attribute on the RHS
This may prove to be a bad idea.
Basically, when a :
is encountered in a terminal position in a lookup chain,
it automatically binds the function at the name being looked up to the rest of the chain.
An example:
var contrived = examples : are : the: { return thismessage } message:"don't you think?" var a_note = contrivedexamplesarethe:best // === "don't you think?" // this actually desugars to: var a_note = contrivedexamplesarethebest // #### WARNING, these are buggy right now. You cannot use them in ?: ternaries. ####
THE UNARY TIGHT-BINDING OPERATOR
: EXPR
returns the function represented by EXPR bound to the current value of
this
.
When used in a unary position, the colon
binds the function to the right to the current value of this
.
var x = { { console } } name:"gary busey"
It binds tighter than most unary operations (due to a gross, hacky solution), so you can write functions like this:
{ thisname = name } { thistoys = toys // ooo: :Childsuperclass }
Multiline Strings
Just adds multiline string support:
var myString = """ hi there""" + ''' 'lol''''
How to use
require
'ing jabbascript will add a require hook for .jsx
files. These files can contain the formulations above.
If you spot any bugs, lemme know. There's sure to be millions.
An admonition
This is very much so a WIP. It is licensed MIT.