Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Very strange behavior when copying util.inspect to a new Object #2225

Closed
indexzero opened this issue Nov 29, 2011 · 5 comments
Closed

Very strange behavior when copying util.inspect to a new Object #2225

indexzero opened this issue Nov 29, 2011 · 5 comments
Labels

Comments

@indexzero
Copy link

I can't even begin to understand what's going on here:

$ node
> var util = require('util')
> var x = {};
> x
{}
> x.inspect = util.inspect;
[Function]
> x
2
> 
@indexzero
Copy link
Author

I can confirm the same behavior in 0.4.x and 0.6.x

@isaacs
Copy link

isaacs commented Nov 29, 2011

The issue is that the sys.inspect function checks for obj.inspect to see if you have some custom inspection. If so, it calls it with the depth, and some other args. Those args are interpreted by sys.inspect to be inspecting the number 2. Crazy, huh?

It checks now for whether or not the object === exports. Maybe instead, it should check for if object.inspect === exports.inspect.

@koichik
Copy link

koichik commented Nov 30, 2011

Related to #410

@TooTallNate
Copy link

I've added a fix for this in #2226. Credit goes to @indexzero for the test case and @isaacs for the fix.

@indutny
Copy link
Member

indutny commented Nov 30, 2011

Ha! I knew it! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants