Extending JavaScript the easy way

1,439 views

Published on

Sergi shows an easy way to extend the syntax of JavaScript without having to create a new language. Using sweet.js macros created by Mozilla's Tim Disney, we can extend our favorite language without making big sacrifices, we can add a few small features to our favorite language or we can create entire DSLs that help with the problem at hand, all in an easy way.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,439
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Extending JavaScript the easy way

  1. 1. Extending JavaScriptthe easy waySergi Mansilla, November 2012
  2. 2. @sergimansilla
  3. 3. JavaScript is popular
  4. 4. It is ASMfor the web
  5. 5. Obj ecti Coco cript ve J C offeeS JS2 FBJS t Jack JS11 Roy rip Sc ax py pJ JWacs Lis F la Streamline JS Elm Type Scrip tSource: http://altjs.org
  6. 6. Be JavaScript, my friend
  7. 7. ...but it is farfrom perfect
  8. 8. Macrosultimate flexibility (ES6 wont have them, btw)
  9. 9. Macros provide a way to extend syntaxSyntax Macro Syntax
  10. 10. Users can extend the language
  11. 11. It helps evolving the language faster
  12. 12. sweet.jsMacros for JavaScript
  13. 13. sweet.js Modeled afterScheme macros
  14. 14. Sweet.js Syntax Macro SyntaxJS + Macros Sweet.js JS
  15. 15. Redefine function
  16. 16. Redefine function
  17. 17. Destructuring
  18. 18. Destructuring
  19. 19. Destructuring
  20. 20. Destructuring
  21. 21. Destructuring
  22. 22. Destructuring
  23. 23. Destructuring
  24. 24. ?
  25. 25. ?
  26. 26. Nice ranges!
  27. 27. case-style assignment
  28. 28. case-style assignment
  29. 29. Use casesTry 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
  30. 30. Start using it nowNode.js> npm install sweet.js> sjs -o output.js test_macros.sjs> node output.jsBrowserhttps://github.com/iammerrick/require-sweet
  31. 31. Questions?
  32. 32. Thanks! @sergimansilla github.com/sergi sergimansilla.com
  33. 33. Referenceshttp://sweetjs.org/https://github.com/mozilla/sweet.jshttp://jlongster.com/why-sweet.js-mattershttp://scriptogr.am/micmath/post/sweet-macros-in-javascripthttps://news.ycombinator.com/item?id=4560691http://youtu.be/_ahvzDzKdB0

×