当 Brendan Eich 谈到向 JavaScript 添加糖和宏时,他的意思是什么?
我目前正在阅读《Coders at Work》,并且正在该章节采访 Brendan Eich。至少可以说,与前面的章节相比,它有点密集。在第 144 页左右,他谈到了向 JavaScript 添加糖和宏。这些术语是什么意思?为什么有人强烈反对添加它们?
I'm currently reading Coders at Work, and I'm at the chapter interviewing 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. What do these terms mean? Why is there backlash against adding them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
语法糖是添加到语言中的附加语法,以便更容易阅读/编写(请参阅 http:// /en.wikipedia.org/wiki/Syntropic_sugar)。
我对 Eich 讨论的内容的记忆是,他现在想向该语言添加语法糖,以便在短期内更容易使用,但这样做的方式将允许新语法在将来可以用宏替换。
宏基本上是您编写的代码,它将代码作为输入并发出代码作为输出。它们通常看起来与函数相似,但不同之处在于它们对代码本身执行转换。例如,阅读此处了解 Lisp 宏将提供更多信息深入的解释。
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).
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.
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.