在 JavaScript 中大写函数会影响代码的解释方式吗?
Does capitalizing a function in JavaScript affect how the code is interpreted?
我在查德·R·亚当斯 (Chad R. Adams) 的书“Mastering JavaScript High Performance”(PacktPub) 中有关计时器的章节中读到,大写函数名称向解释器表明它是一个构造函数。
这还是第一次听说。以前我被引导相信函数大写只是程序员的约定,但现在我不确定。
那么大写会影响我的代码的解释方式吗?
书中的准确引用:
Notice how we renamed Delay3000 on line 22, capitalizing the d. The
purpose of this is to indicate to the JavaScript interpreter that this
is a constructor, a function that requires it to be initialized in
memory.
章节:运算符、循环和定时器 -> 定时器
不,这没有区别。使用 new
关键字可以做到这一点。
大写是一种编码约定,向维护者表明它是一个构造函数。
我在查德·R·亚当斯 (Chad R. Adams) 的书“Mastering JavaScript High Performance”(PacktPub) 中有关计时器的章节中读到,大写函数名称向解释器表明它是一个构造函数。
这还是第一次听说。以前我被引导相信函数大写只是程序员的约定,但现在我不确定。
那么大写会影响我的代码的解释方式吗?
书中的准确引用:
Notice how we renamed Delay3000 on line 22, capitalizing the d. The purpose of this is to indicate to the JavaScript interpreter that this is a constructor, a function that requires it to be initialized in memory.
章节:运算符、循环和定时器 -> 定时器
不,这没有区别。使用 new
关键字可以做到这一点。
大写是一种编码约定,向维护者表明它是一个构造函数。