CoffeeScript的“阵列()”与“新的Array()” [英] CoffeeScript “Array()” vs “new Array()”
本文介绍了CoffeeScript的“阵列()”与“新的Array()”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么不同(如果有的话)
what is the difference (if there is any) between
x = Array()
和
x = new Array()
在CoffeeScript中(或JavaScript用于这一目的)?我应该使用哪一种?
in CoffeeScript (or JavaScript for that purpose)? Which one should I use?
推荐答案
借助规范说:
在阵列
被称为一个函数,而不是作为一个构造函数,它创建和初始化一个新的Array对象。因此,函数调用阵列(...)
相当于对象的创建前pression 新的Array(...)
用相同的参数。
When
Array
is called as a function rather than as a constructor, it creates and initialises a new Array object. Thus the function callArray(…)
is equivalent to the object creation expressionnew Array(…)
with the same arguments.
这篇关于CoffeeScript的“阵列()”与“新的Array()”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文