这是从 Python 借用的符号(搜索“If the form “< code>*identifier” is present"):这意味着标有星号的形式参数将消耗与满足所有其他参数后剩余的实际参数一样多的实际参数。在Python中,“剩下的数量”可能为零,不会出现错误;我不知道 underscore.js 是否属于这种情况(它在相当原始的 Javascript 可变参数函数机制之上实现这些语义,因此它可以做任何它喜欢做的事情)。
This is notation borrowed from Python (search for "If the form “*identifier” is present"): it means that the formal parameter tagged with the asterisk will consume as many actual arguments as are left over after all other parameters are satisfied. In Python, "as many as are left over" may be zero without error; I don't know if that's the case in underscore.js (which is implementing these semantics on top of the rather more primitive Javascript variadic function mechanism, so it can do whatever it likes).
In that particular case it means that _.extend takes zero or more source objects. AFAIK, this notation is specific to Underscore (which probably picked it up from Ruby). The C-style _.extend(destination, source, ...) ellipses is an alternative (and possibly more common) way of noting the same thing.
发布评论
评论(2)
这是从 Python 借用的符号(搜索“If the form “< code>*identifier” is present"):这意味着标有星号的形式参数将消耗与满足所有其他参数后剩余的实际参数一样多的实际参数。在Python中,“剩下的数量”可能为零,不会出现错误;我不知道 underscore.js 是否属于这种情况(它在相当原始的 Javascript 可变参数函数机制之上实现这些语义,因此它可以做任何它喜欢做的事情)。
This is notation borrowed from Python (search for "If the form “
*identifier
” is present"): it means that the formal parameter tagged with the asterisk will consume as many actual arguments as are left over after all other parameters are satisfied. In Python, "as many as are left over" may be zero without error; I don't know if that's the case in underscore.js (which is implementing these semantics on top of the rather more primitive Javascript variadic function mechanism, so it can do whatever it likes).在这种特殊情况下,这意味着
_.extend
需要零个或多个source
对象。 AFAIK,这个表示法是 Underscore 特有的(它可能是从 Ruby 中继承来的)。 C 风格的_.extend(destination, source, ...)
省略号是表示同一事物的另一种(可能更常见)方式。In that particular case it means that
_.extend
takes zero or moresource
objects. AFAIK, this notation is specific to Underscore (which probably picked it up from Ruby). The C-style_.extend(destination, source, ...)
ellipses is an alternative (and possibly more common) way of noting the same thing.