1

What means curly braces around signal?

const controller = new AbortController();
const signal = controller.signal;
readFile(fileInfo[0].name, **{ signal }**, (err, buf) => {
...

Thanks.

  • It's shorthand for an object where the key and the value are the same: `{ signal: signal }` can be written as `{ signal }` – Nick Apr 16 '21 at 02:07
  • @Nick Nitpick: key _name_ and the value variable _name_, not key and value. (Key and value would be same with `{ [signal]: signal }`, or `{ signal: "signal" }`; if `signal` is e.g. `"foo"`, `{ signal }` results in `{ "signal": "foo" }`, with key and value demonstrably not same.) – Amadan Apr 16 '21 at 02:08

2 Answers2

1

If you read the documentation you'll note that the second argument to readfile is options which is an object, one property of which is signal.

Andy
  • 61,948
  • 13
  • 68
  • 95
1

In ES6/ES2015 It's an object property value shorthand:

if you have a variable named signal

const signal = "test"
const ob = {signal};
console.log(ob.signal); // "test"

is equal to ES5's

const signal = "test"
const ob = {signal: signal};
console.log(ob.signal); // "test"
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313