Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8170121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:04:18+00:00 2026-06-06T21:04:18+00:00

in an existing implementation (can’t change the structure much), i’m trying to call a

  • 0

in an existing implementation (can’t change the structure much), i’m trying to call a function which is nested inside another function:

function outer(innerFunction, obj) {

    //TODO: call innerFunction here, passing obj as first parameter

    function inner1(obj) {
        alert(obj.key);
    }
}
outer('inner1', {key:'value'});

jsfiddle is here: http://jsfiddle.net/tbyyw/

i’ve alreay thought about using eval(), but i don’t know how to pass an object – and they say ‘eval is evil’ 😉

another solution i’ve come up with is checking the innerFunction string, but this means i have to know which inner functions exist (besides, adding new functions would mean having to write extra checks then):

if(innerFunction == 'inner1') inner1(obj);

so is there another way without changing the overall implementation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:04:18+00:00Added an answer on June 6, 2026 at 9:04 pm

    Without changing the overall structure eval appears to be the only option:

    function outer(funcName, obj) {
    
        var func = eval(funcName);
        func(obj);
    
        function inner1(obj) {
            alert(obj.key);
        }
    }
    

    There’s nothing particularly “evil” about eval as long as you have full control over the code, but if you want, you can insert an additional security check:

    if (funcName.match(/\W/))
        throw "invalid function name!";
    
    var func = eval(funcName);
    

    This will raise an exception if someone tries to pass anything else than a simple identifier, i.e. a function name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a large implementation of Class::DBI for an existing database structure,
So I'm working to improve an existing implementation. I have a number of polymorphic
Hi I would like to know if there's an existing implementation of checking if
Existing XML webservice Processes XML-RPC style requests in which an operation element which identifies
I'm looking for an ExecutorService implementation that can be provided with a timeout. Tasks
I'm in the process of updating an existing application that currently can only be
I've been working on a REST implementation with my existing Cake install, and it's
Which Tree data structure in Java allows querying for different levels of children? I
I have an existing model implementation that needs to work with a new database.
I'm implementing WCF into an existing application, and as part of the implementation I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.