Improve debug of instances / constructors
Closed this issue · 6 comments
At the moment, if you do a console.log on an instance, weird things come from it.
This is because dejavu uses object.defineProperty to protect private and protected members.
get _compareObjects: function get() {
get _cursor: function get() {
get _name: function get() {
get _params: function get() {
get _pos: function get() {
get getBranchName: function get() {
There is two possible solutions:
- dejavu.inspect -> would return a clone of the instance but would be a common object
- rewrite console methods -> the new methods would behave the same way, except that they take in account instances/constructors
Actually both can live together because the console methods could call dejavu.inspect internally.
NOTE: this only happens in the strict version.
Does anyone have a better solution for this?
This is done, still it needs a lot of tests..
Modifying the console.* methods was easy and works great, but we loose the ability to click the line in the browser console:
Will investigate if we can make it work with source maps.
If we can't it's kind of bad.. and we shouldn't do it. Instead we must warn users to use dejavu.inspect
.
Ok it seems it's not possible.
If the user wants the console.* to use inspect automatically, then they have dejavu.inspect.rewriteConsole() available.
What do you think @marcooliveira?
Alternatives to rewriting console methods:
- Users have to use dejavu.inspect()
- Add a $inspect method to instances/constructors
- Add a console.inspect method
I would say that the .$inspect()
method that returns a simpler copy of the object is the way to go. This is sort of requesting a representable copy of the object.
The dejavu.inspect()
could also be useful, but I think we should stop pushing features right now, until we have more feedback from the community.
As for rewriting the console.*
methods, some users might not appreciate that, even if this is only optional. Once again, let's wait for the community.
@marcooliveira I actually prefer adding console.inspect because:
- easier to use
- don't expose the instance/constructor properties
If one wants to know the value of a private/protected property or to call a private/protected method, $inspect() and dejavu.inspect() would allow it unless they actually do a console.log instead of returning the representable copy of the object.
I see what you mean. I have no objections to using console.inspect()
instead, as long as that's the way to do it (not a fan of multiple ways to do the same thing).
As for being able to use $inspect()
to call protected/private methods, it might be dangerous. Probably not a good idea to have that method, now that you mention it.