在underscore.js的背景:新包装如何在JavaScript中工作?
// Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); };
简单地说,这是什么功能的回报?
在underscore.js的背景:新包装如何在JavaScript中工作?
// Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); };
简单地说,这是什么功能的回报?
It是wrapper
constructor的包装函数,允许您在不使用new
keyword的情况下使用下划线。调用下划线将始终返回一个新的wrapper
实例。
顺便说一句,该wrapper
功能已经在this commit除去。现在_
函数本身就是构造函数,请参阅Understanding the declaration of the underscore in _.js?的解释。
简单地说,它是“包装”,使事情构造一个很大的方便你
// this allows you to do things such as:
var a = _({/*object*/});
// rether than something like:
var a = new wrapper({/*object*/});
我认为在,因为它让你的编码tiddy underscore.js和简单:)
它返回包装类型的新实例。在这里阅读更多关于javascript的对象模型:https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Details_of_the_Object_Model – Esailija 2012-08-06 21:27:26
这是一个面向对象的代码位,基于其他一些JavaScript,你可能会在某个地方。它有包装对象/类。 – chris 2012-08-06 21:28:22