JavaScript 中奇怪的语法
我正在调试其他人编写的一些代码(使用 Mootools 作为基础库),并且我遇到了这个函数:
[note, $H(options.text).getKeys()].flatten().each(function(option){
// bunch of stuff happening
});
我以前从未见过这种语法,带有括号和 $H 符号(例如。 [注意,$H(options.text).getKeys()]
)。谁能解释一下它是如何工作的或者给我指出它的参考资料?
谢谢!
I'm working on debugging some code someone else wrote (using Mootools as the base library), and I came across this function:
[note, $H(options.text).getKeys()].flatten().each(function(option){
// bunch of stuff happening
});
I've never seen this syntax before, with the brackets and the $H notation (eg. [note, $H(options.text).getKeys()]
). Can anyone explain how that works or point me to a reference on it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这基本上将两个数组聚合在一起。以以下代码为例:
数组
[1,2,3]
和[4,5,6]
组合(或“扁平化”)为一个数组,1,2,3,4,5,6
。在您的代码中:
note
(可能是另一个数组),并且getKeys()
返回的任何内容都会被展平为单个数组。然后,对每个元素执行一个函数。更新:
$H 函数 是一个实用函数在 Mootools 中,这是 Hash() 的快捷方式。
This basically aggregates two arrays together. Take, for example, this code:
The arrays
[1,2,3]
and[4,5,6]
are combined (or "flattened") into a single array,1,2,3,4,5,6
.In your code:
note
(perhaps another array) and whatevergetKeys()
returns are flattened into a single array. Then, a function is performed across each element.Update:
The $H function is a utility function in Mootools that is a shortcut for Hash().
最有可能变成:
所以它返回一个数组。因此
["whatever note is", ["Another array", "ofobjects"]]
需要展平为:is most likely becoming:
so it returns an array. So
["whatever note is", ["Another array", "of objects"]]
needs to be flattened to: