Skip to content

Log output for objects without circular references is a mess. #2

@Cerbrus

Description

@Cerbrus

The snippets' console output for logged objects is, quite frankly, a mess.
Objects that contain no circular references are obfuscated beyond recognition. Their structure is no longer obvious.

For example:

const x = {};
const y = [];
const obj = {
  foo: x,
  bar: x,
  baz: {x, y},
  wut: [x, y]
};

console.log(obj);

Now logs:

{
  "foo": {},
  "bar": /**ref:2**/,
  "baz": {
    "x": /**ref:2**/,
    "y": []
  },
  "wut": [
    /**ref:2**/,
    /**ref:4**/
  ]
}

Instead of what you'd expect:

{
  "foo": {},
  "bar": {},
  "baz": {
    "x": {},
    "y": []
  },
  "wut": [
    {},
    []
  ]
}

What do these ref lines actually refer to? Why doesn't it just show the actual data?

I realize it's not trivial to detect the difference between circular and duplicate references, but frankly, I'd rather see a "Circular reference" error than the current state. In the current state, the object's structure is excessively obfuscated. You might as well not log it, as you'd still have to manually figure out what the object contains.

See also my report on Stack Overflow's Meta.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions