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

util: allow symbol-based custom inspection methods #8174

Closed
wants to merge 2 commits into from

Commits on Aug 24, 2016

  1. util: allow symbol-based custom inspection methods

    Add a `util.inspect.custom` Symbol which can be used to customize
    `util.inspect()` output. Providing `obj[util.inspect.custom]`
    works like providing `obj.inspect`, except that the former allows
    avoiding name clashes with other `inspect()` methods.
    
    Fixes: nodejs#8071
    addaleax committed Aug 24, 2016
    Configuration menu
    Copy the full SHA
    bc14ea3 View commit details
    Browse the repository at this point in the history
  2. util: allow returning this from custom inspect

    If a custom inspection function returned `this`, use that value
    for further formatting instead of going into infinite recursion.
    
    This is particularly useful when combined with `util.inspect.custom`
    because returning `this` from such a method makes it easy to
    have an `inspect()` function that is ignored by `util.inspect` without
    actually having to provide an alternative for custom inspection.
    addaleax committed Aug 24, 2016
    Configuration menu
    Copy the full SHA
    2dc6163 View commit details
    Browse the repository at this point in the history