Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

You could do something like this with arrow functions, it works for me on Node.

const createTask = ([name, type = 'default']) => {
 const fn = () => { ... }
 Object.defineProperty(fn, 'name', {
 value: name,
 configurable: true,
 })
 return fn
}

MDN is somewhat misleading here:

You cannot change the name of a function, this property is read-only...

To change it, you could use Object.defineProperty() though.

This answer provides more details.

You could do something like this with arrow functions, it works for me on Node.

const createTask = ([name, type = 'default']) => {
 const fn = () => { ... }
 Object.defineProperty(fn, 'name', {
 value: name,
 configurable: true,
 })
 return fn
}

MDN is somewhat misleading here:

You cannot change the name of a function, this property is read-only...

To change it, you could use Object.defineProperty() though.

This answer provides more details.

You could do something like this with arrow functions, it works for me on Node.

const createTask = ([name, type = 'default']) => {
 const fn = () => { ... }
 Object.defineProperty(fn, 'name', {
 value: name,
 configurable: true,
 })
 return fn
}

MDN is somewhat misleading here:

You cannot change the name of a function, this property is read-only...

To change it, you could use Object.defineProperty() though.

This answer provides more details.

Source Link
Jack Steam
  • 5.4k
  • 3
  • 29
  • 42

You could do something like this with arrow functions, it works for me on Node.

const createTask = ([name, type = 'default']) => {
 const fn = () => { ... }
 Object.defineProperty(fn, 'name', {
 value: name,
 configurable: true,
 })
 return fn
}

MDN is somewhat misleading here:

You cannot change the name of a function, this property is read-only...

To change it, you could use Object.defineProperty() though.

This answer provides more details.

lang-js

AltStyle によって変換されたページ (->オリジナル) /