Slide 1

Slide 1 text

Extending JavaScript the easy way Sergi Mansilla, November 2012

Slide 2

Slide 2 text

@sergimansilla

Slide 3

Slide 3 text

JavaScript is popular

Slide 4

Slide 4 text

It is ASM for the web

Slide 5

Slide 5 text

CoffeeScript LispyScript JWacs FlapJax Elm Coco FBJS JS11 Roy Streamline JS TypeScript Objective J JS2 Jack Source: http://altjs.org

Slide 6

Slide 6 text

Be JavaScript, my friend

Slide 7

Slide 7 text

...but it is far from perfect

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Macros ultimate flexibility (ES6 won't have them, btw)

Slide 10

Slide 10 text

Macros provide a way to extend syntax Syntax Syntax Macro

Slide 11

Slide 11 text

Users can extend the language

Slide 12

Slide 12 text

It helps evolving the language faster

Slide 13

Slide 13 text

sweet.js Macros for JavaScript

Slide 14

Slide 14 text

sweet.js Modeled after Scheme macros

Slide 15

Slide 15 text

Sweet.js Syntax Syntax Macro JS + Macros JS Sweet.js

Slide 16

Slide 16 text

Redefine 'function'

Slide 17

Slide 17 text

Redefine 'function'

Slide 18

Slide 18 text

Destructuring

Slide 19

Slide 19 text

Destructuring

Slide 20

Slide 20 text

Destructuring

Slide 21

Slide 21 text

Destructuring

Slide 22

Slide 22 text

Destructuring

Slide 23

Slide 23 text

Destructuring

Slide 24

Slide 24 text

Destructuring

Slide 25

Slide 25 text

?

Slide 26

Slide 26 text

?

Slide 27

Slide 27 text

Nice ranges!

Slide 28

Slide 28 text

case-style assignment

Slide 29

Slide 29 text

case-style assignment

Slide 30

Slide 30 text

Use cases Try proposed syntax before it makes into the language Create Micro-DSLs for your scenario Use ideas from other languages Make the new Script Implement basic types You get the idea

Slide 31

Slide 31 text

Start using it now > npm install sweet.js > sjs -o output.js test_macros.sjs > node output.js Node.js Browser https://github.com/iammerrick/require-sweet

Slide 32

Slide 32 text

Questions?

Slide 33

Slide 33 text

Thanks! @sergimansilla github.com/sergi sergimansilla.com

Slide 34

Slide 34 text

http://sweetjs.org/ https://github.com/mozilla/sweet.js http://jlongster.com/why-sweet.js-matters http://scriptogr.am/micmath/post/sweet-macros-in- javascripthttps://news.ycombinator.com/item?id=4560691 http://youtu.be/_ahvzDzKdB0 References