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 85307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:04:07+00:00 2026-05-10T22:04:07+00:00

I have the name of a function in JavaScript as a string. How do

  • 0

I have the name of a function in JavaScript as a string. How do I convert that into a function pointer so I can call it later?

Depending on the circumstances, I may need to pass various arguments into the method too.

Some of the functions may take the form of namespace.namespace.function(args[...]).

  • 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. 2026-05-10T22:04:08+00:00Added an answer on May 10, 2026 at 10:04 pm

    Don’t use eval unless you absolutely, positively have no other choice.

    As has been mentioned, using something like this would be the best way to do it:

    window['functionName'](arguments); 

    That, however, will not work with a namespace’d function:

    window['My.Namespace.functionName'](arguments); // fail 

    This is how you would do that:

    window['My']['Namespace']['functionName'](arguments); // succeeds 

    In order to make that easier and provide some flexibility, here is a convenience function:

    function executeFunctionByName(functionName, context /*, args */) {   var args = Array.prototype.slice.call(arguments, 2);   var namespaces = functionName.split('.');   var func = namespaces.pop();   for(var i = 0; i < namespaces.length; i++) {     context = context[namespaces[i]];   }   return context[func].apply(context, args); } 

    You would call it like so:

    executeFunctionByName('My.Namespace.functionName', window, arguments); 

    Note, you can pass in whatever context you want, so this would do the same as above:

    executeFunctionByName('Namespace.functionName', My, arguments); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Here's an implementation of that exercise answer. Perhaps it helps.… May 11, 2026 at 10:47 am
  • added an answer You can also use SQL Server Integration Services to import… May 11, 2026 at 10:47 am
  • added an answer I've used Beej's Guide to Network Programming in the past.… May 11, 2026 at 10:47 am

Related Questions

I have the name of a function in JavaScript as a string. How do
Assuming I have only the class name of a generic as a string in
I have a string variable that represents the name of a custom class. Example:
In a Python package, I have a string containing (presumably) the name of a
I have a vs.net project, and after some refactoring, have modified the name of
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a huge bunch of XML files with the following structure: <Stuff1> <Content>someContent</name>
I have this in my installer and I need to change the name of
Here is my issue. I have an array containing the name of cities that
Let's say I have the following objects: squirrel_table - name - country_of_origin - id

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.