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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:19:58+00:00 2026-05-14T01:19:58+00:00

The intention is to build a wrapper to provide a consistent method of calling

  • 0

The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts – so that the script could be executed in a browser as well as in the Windows Script Host or other script engines.
I am aware of 3 methods of which each one has its own drawbacks.

  1. eval() method:

    function wrapper () {
        var str = '';
        for (var i=0; i<arguments.lenght; i++)
            str += (str ?', ':'') + ',arguments['+i+']';
        return eval('[native_function] ('+str+')');
        }
    
  2. switch() method:

    function wrapper () {
        switch (arguments.lenght) {
            case 0:
                return [native_function] (arguments[0]);
                break;
            case 1:
                return [native_function] (arguments[0], arguments[1]);
                break;
            ...
            case n:
                return [native_function] (arguments[0], arguments[1], ... arguments[n]);
            }
        }
    
  3. apply() method:

    function wrapper () {
        return [native_function].apply([native_function_namespace], arguments);
        }
    

What’s wrong with them you ask?

  1. Well, shall we delve into all the reasons why eval() is evil? And also all the string concatenation… Not a solution to be labeled “elegant”.

  2. One can never know the maximum n and thus how many cases to prepare. This also would strech the script to immense proportions and sin against the holy DRY principle.

  3. The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don’t support the apply() method.

Now the question part: is there any another solution out there?

  • 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-05-14T01:19:59+00:00Added an answer on May 14, 2026 at 1:19 am

    Just use apply(). And for your antiquated execution engines, just do this

    if ( 'undefined' == typeof Function.prototype.apply )
    {
      Function.prototype.apply = function( context, args )
      {
        // whatever hacky way you want to implement it - i guess eval.
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no intention of using My for anything in any of my projects.
I am connecting to CRM with the intention of retrieving a list of picklist
I'm working on a casual game on XNA with the intention of deploying to
I have a WCF service hosted in IIS. The intention is for clients to
My intuition was Lorem ipsum\footnote{long footnote that spans a whole bunch of lines. }
I have a large .NET web application. The system has projects for different intentions
Dependency injection seems to be a good thing. In general, should dependencies be injected
Which C#/.NET Dependency Injection frameworks are worth looking into? And what can you say
I know SQL Injection is one... what are the others...
When reading about SQL Injection and XSS i was wondering if you guys have

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.