Skip to content

$inspect(...).with(...) #9737

Closed
Closed
@Rich-Harris

Description

@Rich-Harris

Describe the problem

Some feedback we've had on $inspect is that this...

console.log('>>> HERE', foo, bar, baz);

...is a common pattern that doesn't work with $inspect, as it only takes a single value argument (in order to prevent ambiguity when providing a callback function).

Describe the proposed solution

@dummdidumm had a great idea — allow an arbitrary number of arguments, and put the callback in a .with method:

// these are effectively identical
$inspect('>>> HERE', foo, bar, baz);
$inspect('>>> HERE', foo, bar, baz).with(console.log);

// can also use `console.trace` or `debugger`...
$inspect('>>> HERE', foo, bar, baz).with(console.trace);

$inspect('>>> HERE', foo, bar, baz).with((type, ...values) => {
  debugger;
});

// ...or whatever custom logic you want to provide
$inspect('>>> HERE', foo, bar, baz).with((type, ...values) => {
  klaxon.play();
});

Alternatives considered

n/a

Importance

nice to have

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions