镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

console: console.table doesn't fall back to just logging when given a function #20679

Closed

Description

@ohbarye
  • Version: v10.1.0
  • Platform: macOS X
  • Subsystem: console

This is a question. (And I admit it's a kind of nitpicking).

Current Behavior

According to the console.table document, it reads that it "falls back to just logging the argument if it can’t be parsed as tabular."

But it doesn't fall back when I give a function as its first argument. It logs an empty table.

$ node

> const f = function() {}
> console.table(f)
┌─────────┐
│ (index) │
├─────────┤
└─────────┘
$ node

> class Test {}
> console.table(Test)
┌─────────┐
│ (index) │
├─────────┤
└─────────┘

I guess that's because the following line allows a function to proceed the consequent steps.

(typeof tabularData !== 'object' && typeof tabularData !== 'function'))

Question

Is this intentional behavior?

If it's better to change this behavior, I would be glad to send a patch for that.

Activity

  1. added
    consoleIssues and PRs related to the console subsystem.
    on May 11, 2018
  2. devsnek commented on May 11, 2018

    @devsnek
    Member

    i think it'd be fine to change it

  3. Trott commented on May 11, 2018

    @Trott
    Member

    I think this was intentional behavior. It's what Chrome does and it fits my interpretation of the spec. However, Firefox does it differently and the spec for console.table() is just a few sentences long so not very detailed.

    Do note that it's possible to attach properties to a function and that our current implementation deals with that well:

    $ ./node
    > foo = function () {}
    [Function: foo]
    > foo.bar = 'hey'
    'hey'
    > console.table(foo)
    ┌─────────┬────────┐
    │ (index) │ Values │
    ├─────────┼────────┤
    │   bar   │ 'hey'  │
    └─────────┴────────┘
    undefined
    >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    consoleIssues and PRs related to the console subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions