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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:29:11+00:00 2026-05-27T15:29:11+00:00

I am working with prototype methods and here is the scenerio function Foo ()

  • 0

I am working with prototype methods and here is the scenerio

function Foo () {
    this.x = 5;
    this.y = 2;
    this.z = this.addValues();
}
Foo.prototype = {
    addValues:  function (){
        return this.x + this.y; 
    }
}

Obviously this is just a simple example; in real project, there will be lot of activities in the ‘addValue’ function. Is it fine to use ‘this’ keyword 100s of times or caching this to local variable helps any performance improvements. For example, the below will make any difference?

Foo.prototype = {
    addValues:  function (){
        var self = this;
        return self.x + self.y; 
    }
}
  • 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-27T15:29:12+00:00Added an answer on May 27, 2026 at 3:29 pm

    this is the standard way to access x and y. You’ll get no improvements from caching this to a local var—if anything, you’re wasting space by declaring self in the first place.

    The only possible risk you’d see is with something like this:

    var f = new foo();
    var stupid = f.addValues;
    stupid(); // whoops - this is suddenly the global object, 
              // and your method is broken.
    

    Having said that, I don’t think you’re responsible for people misusing your function, and I wouldn’t worry about it.

    Also, by convention, functions meant to be used as constructors should start with a capital letter. Consider renaming foo to Foo

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

Sidebar

Related Questions

Here is the code <script> String.prototype.testthing = function() { return working; } alert(String.testthing()); </script>
I have a simple code fragment in JS working with prototype inheritance. function object(o)
I'm working on a Javascript class based on the Prototype library. This class needs
I've just started building a prototype application in Django. I started out by working
In this code I created a function called someFunction. Then I modified Function.prototype.apply and
Working on an AJAX class. Here is the code: function AjaxRequest(params) { if (params)
I'm following the tutorial here: http://docs.jquery.com/Plugins/Authoring I just wanted to create a simple plugin
Am I mistaking what .prototype is supposed to do, or is this just not
Hi! I have a working prototype of a game engine and right now I'm
Prototype working ternary device Quantum computing with qbits and so on is one thing,

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.