-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
minor request on logging classes #32270
Comments
I think implementing this could call |
@addaleax I already have a local implementation that does exactly that. It is a bit tricky handling the edge cases though. E.g. |
It's a start... typeof v === 'function'
&& v.prototype // undefined if arrow fn
&& v.constructor?.name !== 'GeneratorFunction'
&& /^class\s/.test(Function.prototype.toString.call(v)) maybe should be some native builtin way to handle it. on a side note i notice that chrome devtool also prints |
I'm -1 on testing for |
@devsnek if I understand correct you worry about people relying upon the suggested class output in a way that it's always possible to invoke all functions without I would not worry about that since it's no guarantee, just an indicator? |
based on the OP it seems like people would rely on this. my concern is that something this finicky it might just end up being noise. |
honestly I wouldn't rely on it that much. I just don't see classes as a function so i don't think they should be named as such to begin with.
i.e: not a function that you can call and expect something to happen or give you a result. it's something you instantiate. it's like @BridgeAR said: it's no guarantee, just an indicator to help you distinguish things out from the mass. and helping you figure out what things are a little bit earlier. -- @BridgeAR, do you mind sharing your local implementation that solves this? |
@jimmywarting regardless of where this issue goes, i'd suggest changing your mental model of classes because they're just sugar for |
@jimmywarting I just opened a PR to implement this. It includes lots of edge cases in the tests in case you are interested in that. Chromium just prints the plain stringified value while this strips comments and adds further information. |
When logging object, functions and classes you sometimes see function and classes being printed the same way as such:
I wish they where a bit more distinguish if it is a function or a class so you know if you have to call the
"function"class with thenew
keyword and expect something backkinda like chrome's devtool:
with the prefixed
class
andf
in the beginningmaybe with an other color (same as the number color - orange) or like my atom editor:
it's not so much about styling, (the above are just some suggestions)
the request feature is just more about distinguish classes from functions in the terminal
(don't mind as much if this is being discarded and closed since it's not so important to me - just wishful)
The text was updated successfully, but these errors were encountered: