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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:32:54+00:00 2026-06-01T18:32:54+00:00

Below, is a simplified version of my App , the following code works as

  • 0

Below, is a simplified version of my App, the following code works as intended. I can see 4 logs in my console with the arguments I passed to SayHello.

var App = {};

(function(that){

    that.SayHello = function(){
        console.log( arguments );
        return {
            doSomething: function(){
                console.log('done');
            }
        };
    };

    var obj = {
        t: new that.SayHello( 'a', 1 ),
        r: new that.SayHello( 'b', 2 ),
        b: new that.SayHello( 'c', 3 ),
        l: new that.SayHello( 'd', 4 )
    };

}(App));

issue: I am trying to create a “shortcut” to new that.SayHello as follow:

var Greet = function(){
        return new that.SayHello;
    },
    obj = {
        t: Greet( 'a', 1 ),
        r: Greet( 'b', 2 ),
        b: Greet( 'c', 3 ),
        l: Greet( 'd', 4 )
    };

The console logs 4 empty arrays. Wich means the arguments failed to pass.

I also tried return new that.SayHello.apply(this, arguments); and return new that.SayHello.call(this, arguments);.

How can I pass ALL Greet‘s arguments to that.SayHello ?
Knowing that I have to initialize that.SayHello using new that.SayHello or else my code breaks.

I am looking for a general solution for any number of arguments, I don’t want to pass the arguments one by one.

This code is also available on jsfiddle.

  • 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-01T18:32:55+00:00Added an answer on June 1, 2026 at 6:32 pm

    Something like this?

    var Greet = function(){
        var result = that.SayHello.prototype;
        that.SayHello.apply(result, arguments);
        return result;
    }
    

    You should know that apply applies arguments to object result. Predefining result as a SayHello prototype will give you what you want.

    EDIT

    Unfortunetly the code above will alter the prototype of SayHello. This is obviously unwanted behaviour so to avoid this I think we should copy the prototype object. For example use the following code

    function clone(obj) {
        if (null == obj || "object" != typeof obj) return obj;
        var copy = obj.constructor();
        for (var attr in obj) {
            if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
        }
        return copy;
    }
    
    var Greet = function(){
        var result = clone(that.SayHello.prototype);
        that.SayHello.apply(result, arguments);
        return result;
    }
    

    I’ve found this simple version of clone function in this answer. There are many problems with it and you should check other answers. For example using jQuery’s $.extend({},originalObject) might be a good idea.

    Note that if you don’t care about prototype chaining (although you should) you can always do something very simple like this:

    var Greet = function(){
        var result = {};
        that.SayHello.apply(result, arguments);
        return result;
    }
    

    If you don’t care about older browsers (ECMAScript 5) then you can use Object.create method:

    var Greet = function(){
        var result = Object.create(that.SayHello.prototype);
        that.SayHello.apply(result, arguments);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below is a simplified version of my website. On my site, the
Ok, here is setup. Note the code below is SIMPLIFIED version. PHP 5.2 ENGINE:
Below is a simplified version of a segment of code that I'm working on
The code below is a simplified version of the pattern my project is using.
I have a method (the code below is a simplified version) that parses small
A simplified version of the code is posted below (white space, comments, etc. removed
The following code snippet is a simplified version of my issue. Basically I'm trying
The code below is a simplified version of my task bar icon class, I
Below is a simplified version of code I've written to override a class method
I've simplified my JavaScript code to the example below; this code is giving me

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.