签名文档中 * 的含义

发布于 2024-12-21 13:03:21 字数 173 浏览 1 评论 0原文

函数签名中 * 的含义是什么

_.extend(destination, *sources) 

请参阅此处查看示例。

What does * mean in the function signature

_.extend(destination, *sources) 

See here for an example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-12-28 13:03:21

这是从 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).

红玫瑰 2024-12-28 13:03:21

在这种特殊情况下,这意味着 _.extend 需要零个或多个 source 对象。 AFAIK,这个表示法是 Underscore 特有的(它可能是从 Ruby 中继承来的)。 C 风格的 _.extend(destination, source, ...) 省略号是表示同一事物的另一种(可能更常见)方式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文