Skip to content

Adding a method named 'inspect' to an object does not work as expected #1798

Closed
@toddself

Description

@toddself

I understand this has probably been like this for a while but I've never created a method named inspect on an object. Just spent over two hours trying to debug this.

At the very least this should be very well documented. Right now the first link in Google for node inspect reserved is a stackoverflow answer and there is no mention of this behavior in the documentation.

Obviously running this code in Chrome, Firefox, Safari, etc works as expected.

> process.versions
{ http_parser: '2.5.0',
  node: '2.0.2',
  v8: '4.2.77.20',
  uv: '1.5.0',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  modules: '44',
  openssl: '1.0.2a' }
> function Test(){ };
undefined
> Test.prototype.inspect = function(){ return 'hahaha';}
[Function]
> var t = new Test()
undefined
> t
hahaha

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions