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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:19:56+00:00 2026-06-04T05:19:56+00:00

Where I reference to a JavaScript object multiple times using this var myObj =

  • 0

Where I reference to a JavaScript object multiple times using this

var myObj = {
   method1 : function() {},
   method2 : function() {},
   method3 : function {},
   init : function() {
       this.method1();
       this.method2(); 
       this.method3();  
   }
};

Is there any kind of performance gain and should I store this in a variable? Like:

init : function() {
    var self = this;

    self.method1();
    self.method2(); 
    self.method3();  
}
  • 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-04T05:19:58+00:00Added an answer on June 4, 2026 at 5:19 am

    There is no need to store the this reference in a variable, unless you need to pass that context into a closure.

    Here is an example of when you may need to pass the this pointer into a closure, such as a click event on an element that needs a reference to whatever the this pointer was pointing to in the outer, parent context of the event:

    init : function() {
    
        $('.someElem').click( 
            (function(self) {
                return function() {
                    self.method1();
                    self.method2(); 
                    self.method3();  
                }
            })(this)   // pass "this" into the "self" parameter as an argument
        );
    
    }
    

    In your case, you’re needlessly creating a local variable and assigning it something when you really don’t need to. It’s redundant, and also creates a variable that isn’t needed.

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

Sidebar

Related Questions

If in javascript object properties are passed by reference why this doesnt work: var
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty states: configurable : True if and only if the type of this property
I currently have a Javascript function that uses a string to reference an object
stated here https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function the constructor property of an instance of a function object specifies
I have a javascript object like this var obj={ a:{x: someValue, y:anotherValue}, b:{x: bValue,
I tried to search for a JavaScript reference, but there's none available. The best
With the reference to this question:- JavaScript -Change CSS color for 5 seconds Working
Is it possible in javascript to assign an alias/reference to a local var someway?
I'm trying to wrap my head around Javascript's function.apply(). You use it like this:
Using Firefox, working on a Firefox extension, I continually get a javascript warning: reference

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.