gpt4 book ai didi

javascript - 下划线函数有什么用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:43 27 4
gpt4 key购买 nike

我一直在使用下划线作为静态集合。

什么是 underscore功能:

var _ = function(obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
};

请举例说明如何使用它?

最佳答案

您还可以使用 Underscore 作为包装函数,以获得更多 OOP-like style :

_(val).method(…);
// instead of the equal
_.method(val, …);

这些包装器对象还允许 chaining :

_.chain(val).method1(…).method2(…);
// or
_(val).chain().method1(…).method2(…);

关于javascript - 下划线函数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16378628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com