Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
How to change Javascript function name that appears in toString()?

Function.name property is configurable and can be overriden, but if I try

function foo() {}
Object.defineProperty(foo, 'name', {value: 'bar'})

foo.toString() still shows up as "function foo() {}" but I expected it to be "function bar() {}".

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't do this 100% reliably. That's because of the definition of Function.prototype.toString, which uses the [[SourceText]] internal slot, which is set as the function is being created from the source code that was used to create the function. It doesn't use the name property.

You could try to override toString on the function as well, but of course that would still fail if someone explicitly used Function.prototype.toString on it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!