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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:50:55+00:00 2026-06-03T04:50:55+00:00

In John Resig’s post on Simple Class Instantiation in Javascript , he states: …if

  • 0

In John Resig’s post on Simple “Class” Instantiation in Javascript, he states:

“…if you have a frequently-accessed function (returning an object) that you want people to interact with, then it’s to your advantage to have the object properties be in the prototype chain and instantiate it. Here it is, in code:”

// Very fast
function User(){}
User.prototype = { /* Lots of properties ... */ };
// Very slow
function User(){
    return { /* Lots of properties */ };
}

I would like to apply this to a function like the following (which happens to live inside a “class” declaration)

//...
this.get_subscription = function(args)
{
    return {
        property_one: "value",
        property_two: {
            sub_prop: args.something
        }
    }
}

but have no idea where to put the args. If I do

this.get_subscription = function(args) {}
this.get_subscription.prototype = {
    property_one: "value"
    //...
}

it’ll say args are undefined. I’ve tried several variants, none of which work. How should I properly do this, in a way that doesn’t put args in the parent class’s scope?

  • 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-03T04:50:56+00:00Added an answer on June 3, 2026 at 4:50 am

    Yes, that’s the drawback of the “everything-to-prototype”-idea: You don’t have access to the constructor arguments – they are only available inside the function body (exept you put them into a public property there). Everything that needs to use them does not belong to the prototype; you only will fill “default properties” on the prototype (usually methods that are common to all instances).

    I think that you don’t need that anyway in here. The pattern is only useful for real constructor functions, which you don’t seem to have here (I then would expect this.Subscription). Also, the promised “performance boost” is negligible.

    If you really would want to use it in here, it would be:

    function Class() {
       this.Subscription = function(args) {
           this.propertyTwo = {
               subprop: args.something
           };
       };
       this.Subscription.prototype = {
           property_one: "value",
           property_two: {}
       };
    }
    // a method callable without the "new" operator:
    Class.prototype.get_subscription = function(args) {
         return new this.Subscription(args);
    }
    

    usage:

    var object = new Class();
    var sub = new object.Subscription();
    var sub2 = new object.Subscription();
    // the promised boost is less memory usage for:
    sub.propertyOne === object.Subscription.prototype.propertyOne === sub2.propertyOne;
    

    Also care for Crockford's Prototypal inheritance – Issues with nested objects when you attempt to set/change/delete properties on the propertyTwo-Object(s).

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

Sidebar

Related Questions

I have a custom Javascript class (created using John Resig's Simple Javascript Inheritance ).
I am using John resig's implementation class mentioned here: http://ejohn.org/blog/simple-javascript-inheritance/ Now I have a
So I've seen this post on JavaScript Micro-Templating by John Resig and I have
I'm using John Resig's excellent javascript class for simple javascript inheritance and I'm having
John Resig’s Simple Javascript Inheritance: http://ejohn.org/blog/simple-javascript-inheritance/ I tried to do such thing: var SomeClass
I was reading John Resig's Secrets of JavaScript Ninja and saw this code: function
I decided to try out JavaScript genius John Resig's simple JavaScript inheritance as detailed
I am using John Resig's JavaScript class definition style . Below is an example
I've been using John Resig's getStyle function from Pro JavaScript Techniques to get the
http://ejohn.org/blog/building-a-javascript-library/ In the above link John Resig Suggests calling and returning new foo in

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.