26

I am learning backbone.js, in it's tutorial, it has the following code

var object = {};
_.extend(object, Backbone.Events);
...

I don't understand the "_" in the code, what does it means? and what is this "extend"? does it has the same meaning as jQuery.extend ?

1
  • 3
    _ is the underscore object. It is defined in underscore.js, a dependency of backbone.js. _.extend is not the same function as $.extend (although I think it does the same thing)
    – Bart
    Commented Mar 24, 2011 at 11:26

2 Answers 2

23

From Backbone's own homepage :

Backbone's only hard dependency is Underscore.js.

_ is the object created by Underscore.js, in the same way as $ is the jQuery object

http://documentcloud.github.com/underscore/#extend as for what _.extend does.

17

It copies all the Backbone.Events properties over to the object. Extend is a method from the underscore library: http://documentcloud.github.com/underscore/#extend

I'd say it's the same as the jQuery method.

Not the answer you're looking for? Browse other questions tagged or ask your own question.