Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After using extend function, the child name is not appropriate #4079

Open
ethan-cao opened this issue Sep 27, 2016 · 2 comments
Open

After using extend function, the child name is not appropriate #4079

ethan-cao opened this issue Sep 27, 2016 · 2 comments

Comments

@ethan-cao
Copy link

ethan-cao commented Sep 27, 2016

As in the definition of var extend = function(protoProps, staticProps) ,
child = function(){ return parent.apply(this, arguments); };
the return child function's name is set as 'child'.

Thus, any new object created by the child function, when you inspect them in Chrome, the name of constructor is displayed as 'child'.
image

Would it be better to display the name of constructor using parent constructor's name ?

From my point of view, it gives developers intuitive overview what the object essentially is. In previous case, "Backbone.Collection" should be displayed after todos.
image
Because
image

I was using the todo list example http://todomvc.com/examples/backbone/

@ethan-cao
Copy link
Author

I am willing to provide a solution. Before doing that, I would like to know whether it is really valuable for most developers.

@jgonggrijp
Copy link
Collaborator

There are two possible solutions:

  1. Use a different class emulator, such as the one built into ES6. A big disadvantage of this approach is that some plugins override extend in order to customize class emulation, so you either have to forgo those plugins or use different class emulation conventions side by side.
  2. Change the definition of extend in a way similar to the following, so that it uses the name of the parent constructor, or something based off it.
    • Initialize child = parent.name. This step can be customized to derive a name rather than copying it directly.
    • Create an empty wrapper object, say container.
    • In the remainder of the function, replace child by wrapper[child].

This has a very low priority as far as I'm concerned, because classes in JavaScript are an illusion anyway, but pull requests for option 2 are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants