在underscore.js:
的上下文中// Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); };
简单地说,这个函数返回什么?
答案 0 :(得分:1)
It是wrapper
constructor的包装函数,允许您在没有new
keyword的情况下使用下划线。调用下划线将始终返回一个新的wrapper
实例。
顺便说一下,wrapper
功能已在this commit中删除。 _
函数本身就是构造函数,请参阅Understanding the declaration of the underscore in _.js?以获取解释。
答案 1 :(得分:0)
简单地说,它是'包装器'的构造函数,使事情变得更容易
// this allows you to do things such as:
var a = _({/*object*/});
// rether than something like:
var a = new wrapper({/*object*/});
我认为在underscore.js之后,它是为了让你的编码保持整洁和简单:)