Backbone-Debugger
Backbone-Debugger copied to clipboard
Document how to use component names functionality
Hi,
I'm having trouble figuring how to use the new component names functionality--in particular I can't figure out how to set the name property of the constructor. Would you be able to provide an example? My best guess is something like this but it doesn't seem to work:
TestView = Backbone.View.extend({
initialize: function () {
}, {
name: "TestView"
}
})
Thanks for the great extension!
Hi, you can specify the constructor name by providing a named function for the "constructor" property:
TestView = Backbone.View.extend({
constructor: function TestView() {
Backbone.View.apply(this, arguments);
}
})
The constructor.name is used for all the components categories, in addition to that, the "title" or "name" attribute is used for Model as an additional name, the url property is used for Collection as an alternative to the constructor.name.
Maybe I should add a wiki page for explaining this, but the purpose is to use an heuristic that works in most cases.
Ok got it! Thanks for your help.
+1 to documenting this. I wasn't getting many names in Backbone-Debugger with Coffeescript (since coffeescript doesn't support function w/names).
Yeah, maybe it's time to add some documentation about that and other features. In the meantime, take a look at the pull request that introduced the functionality, if you have some ideas for improving it fell free to post them there.