Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate macros in JavaScript?

I know that JavaScript doesn't support macros (Lisp-style ones) but I was wondering if anyone had a solution to maybe simulate macros? I Googled it, and one of the solutions suggested using eval(), but as he said, would be quite costly.

They don't really have to be very fancy. I just want to do simple stuff with them. And it shouldn't make debugging significantly harder :)

like image 859
Anders Rune Jensen Avatar asked Oct 11 '08 01:10

Anders Rune Jensen


2 Answers

You could use parenscript. That'll give you macros for Javascript.

like image 149
Luís Oliveira Avatar answered Sep 28 '22 01:09

Luís Oliveira


A library by Mozilla (called SweetJS) is designed to simulate macros in JavaScript. For example, you can use SweetJS to replace the function keyword with def.

like image 34
Anderson Green Avatar answered Sep 28 '22 01:09

Anderson Green