什么是下划线功能? [英] What is the underscore function for?
本文介绍了什么是下划线功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用下划线作为静态的集合。
I've been using underscore as a collection of statics.
什么是下划线函数:
var _ = function(obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
};
您将如何使用此示例?
推荐答案
您还可以使用Underscore作为包装函数,以获得更多类似OOP的样式:
You also can use Underscore as a wrapper function, to get a more OOP-like style:
_(val).method(…);
// instead of the equal
_.method(val, …);
这些包装器对象也允许链接:
These wrapper objects also allow chaining:
_.chain(val).method1(…).method2(…);
// or
_(val).chain().method1(…).method2(…);
这篇关于什么是下划线功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文