Backbone-Debugger icon indicating copy to clipboard operation
Backbone-Debugger copied to clipboard

Document how to use component names functionality

Open johngalambos opened this issue 11 years ago • 4 comments

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!

johngalambos avatar Jun 20 '13 15:06 johngalambos

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.

Maluen avatar Jun 21 '13 12:06 Maluen

Ok got it! Thanks for your help.

johngalambos avatar Jun 21 '13 15:06 johngalambos

+1 to documenting this. I wasn't getting many names in Backbone-Debugger with Coffeescript (since coffeescript doesn't support function w/names).

timmfin avatar Sep 25 '13 16:09 timmfin

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.

Maluen avatar Sep 25 '13 20:09 Maluen