简体   繁体   English

Brendan Eich 在谈到向 JavaScript 添加糖和宏时是什么意思?

[英]What does Brendan Eich mean when he speaks about adding sugar and macros to JavaScript?

I'm currently reading Coders at Work, and I'm at the chapter interviewing Brendan Eich.我目前正在阅读 Coders at Work,我正在采访 Brendan Eich 的那一章。 It's a little dense compared to the preceding chapters, to say the least.至少可以说,与前面的章节相比,它有点密集。 Around page 144, he talks about adding sugar and macros to JavaScript.在第 144 页左右,他谈到了向 JavaScript 添加糖和宏的内容。 What do these terms mean?这些术语是什么意思? Why is there backlash against adding them?为什么会有反对添加它们的强烈反对?

Syntactic sugar is additional syntax added to a language in order to make it easier to read/write (see http://en.wikipedia.org/wiki/Syntactic_sugar ).语法糖是添加到语言中的附加语法,以使其更易于读/写(参见http://en.wikipedia.org/wiki/Syntactic_sugar )。

My recollection of what Eich was discussing is that he wanted to add syntactic sugar to the language now so it would be easier to use in the near term but do so in a way that would allow that new syntax to be replaceable with macros in the future.我记得 Eich 正在讨论的是,他现在想在语言中添加语法糖,以便在短期内更容易使用,但这样做的方式将允许新语法在未来可以用宏替换.

Macros are basically code that you write which take code for input and emit code as output.宏基本上是您编写的代码,它们将代码作为输入并发出代码作为输出。 They often look similar to functions but differ in that they are performing transformations on the code itself.它们通常看起来与函数相似,但不同之处在于它们对代码本身执行转换。 Reading about Lisp macros here for example would provide a more in-depth explanation.例如,在此处阅读 Lisp 宏将提供更深入的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM