Extending javascript with keywords

You can't add keywords to the language but everything is an object and everything can be extended with prototyping.

I wouldn't normally link to crockford but he actually has quite a decent coverage of this , which will afford you syntax of the form foo.inherits(bar); which is about as good as one could wish for. This is quite a common pattern.


Several JavaScript macros systems have been developed for this purpose, including sweet.js. Using the Sweet.js macro system, you can replace one keyword with another keyword (for example, replacing the function keyword with a def keyword.) However, in order to run sweet.js scripts, you must first compile them to JavaScript using the sweet.js compiler.