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

306
Views
Save JavaScript script text string as function variable to call it

I am fetching a JS script from a server, and getting the following string back:

(function(e){function t(t){for(var r,a,o=t[0],c=t[1] .....

I want to save it as a function variable so I can call it (and pass an argument).

I tried wrapping the string with a return (as suggested here) and then use Function() constructor to call it in order get the original function, but it returns undefined.

How can I do this?

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

0

Did you try eval https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

eval is a function that evaluates even if it is a function in string

something like this

const yourVariable = eval("function fromServerResponse(){console.log('executed');}")
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!