34
Extending JavaScript the easy way Sergi Mansilla, November 2012

Extending JavaScript the easy way

Embed Size (px)

Citation preview

Extending JavaScriptthe easy waySergi Mansilla, November 2012

JavaScript is popular

It is ASM for the web

CoffeeScriptLi

spyS

cript

JWacsFlapJax

Elm

Coco

FBJS JS11

Roy

Streamline JSTypeScript

Objective J

JS2Jack

Source: http://altjs.org

Be JavaScript, my friend

...but it is far from perfect

Macrosultimate flexibility

(ES6 won't have them, btw)

Macros provide a way to extend syntax

Syntax SyntaxMacro

Users can extend the language

It helps evolving the language faster

sweet.jsMacros for JavaScript

sweet.js

Modeled afterScheme macros

Sweet.js

Syntax SyntaxMacro

JS + Macros JSSweet.js

Redefine 'function'

Redefine 'function'

Destructuring

Destructuring

Destructuring

Destructuring

Destructuring

Destructuring

Destructuring

?

?

Nice ranges!

case-style assignment

case-style assignment

Use cases

Try proposed syntax before it makes into the languageCreate Micro-DSLs for your scenarioUse ideas from other languagesMake the new <your-silly-name-here>ScriptImplement basic typesYou get the idea

Start using it now

> npm install sweet.js> sjs -o output.js test_macros.sjs> node output.js

Node.js

Browserhttps://github.com/iammerrick/require-sweet

Questions?