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

386
Views
la mejor manera de reemplazar un eval ("nuevo objeto ()")

Estoy buscando la mejor manera de reemplazar eval("nuevo objeto();" )

La fea fuente:

 //var type = window.$(droppedDomNode).data("shape"); var type = "sankey.shape.Start"; var figure = eval("new "+type+"();"); // create a command for the undo/redo support var command = new draw2d.command.CommandAdd(this, figure, x, y);

El eval crea un nuevo objeto sankey.shape.Start.

Estoy buscando la mejor solución para reemplazar este tipo de código.

Gracias

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

0

Construiría un objeto (mapeo) de funciones de constructor.

 const constructors = { "sankey.shape.Start": () => new sankey.shape.Start(), // etc... (this could be built programmatically) };

Después,

 const figure = constructors[type]();
about 4 years ago · Juan Pablo Isaza Report

0

Puede dividirlo y recorrer el camino desde la ventana si es global

 var foo = { bar: { world: 'baz', } } const getIt = (str, start = window) => { return str.split(/\./).reduce((o, k) => o[k], start); } const x = "foo.bar.world"; console.log(getIt(x))

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!