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

  • Home
  • SEARCH
  • 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 3978200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:01:05+00:00 2026-05-20T05:01:05+00:00

I know the possibility to call a function with an array of arguments with

  • 0

I know the possibility to call a function with an array of arguments with apply(obj,args);
Is there a way to use this feature when creating a new instance of a function?

I mean something like this:

function A(arg1,arg2){
    var a = arg1;
    var b = arg2;
}

var a = new A.apply([1,2]); //create new instance using an array of arguments

I hope you understand what i mean… ^^^

Thanks for your help!

Solved!

I got the right answer. To make the answer fit to my question:

function A(arg1,arg2) {
    var a = arg1;
    var b = arg2;
}

var a = new (A.bind.apply(A,[A,1,2]))();
  • 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-20T05:01:06+00:00Added an answer on May 20, 2026 at 5:01 am
    var wrapper = function(f, args) {
        return function() {
            f.apply(this, args);
        };
    };
    
    function Constructor() {
        this.foo = 4;
    }
    var o = new (wrapper(Constructor, [1,2]));
    alert(o.foo);
    

    We take a function and arguments and create a function that applies the arguments to that function with the this scope.

    Then if you call it with the new keyword it passes in a new fresh this and returns it.

    The important thing is the brackets

    new (wrapper(Constructor, [1,2]))

    Calls the new keyword on the function returned from the wrapper, where as

    new wrapper(Constructor, [1,2])

    Calls the new keyword on the wrapper function.

    The reason it needs to be wrapped is so that this that you apply it to is set with the new keyword. A new this object needs to be created and passed into a function which means that you must call .apply(this, array) inside a function.

    Live example

    Alternatively you could use ES5 .bind method

    var wrapper = function(f, args) {
        var params = [f].concat(args);
        return f.bind.apply(f, params);
    };
    

    See example

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

Sidebar

Related Questions

I would know if there is the possibility to create a new Android Activity
I would like to know if there is a possibility to detect if the
I know there are a lot of questions out there about this - believe
Is there a possibility to literally override a target or emulate this somehow? So,
I know there's the possibility, using jQuery, to mix Multiple Selector with Multiple Attribute
Is there any possibility of retrieving missed phone call numbers from WP7? As far
There is this issue I am struggling with. I know that the autoload for
Does anybody know a possibility to center simple pictures within a UIWebview without using
Does anyone know a possibility to protect a string-wildcard from changing in a TextArea?
Know this might be rather basic, but I been trying to figure out how

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.