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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:07:36+00:00 2026-05-13T10:07:36+00:00

Quick question, and one I am yet to work out on my own. I’ll

  • 0

Quick question, and one I am yet to work out on my own. I’ll start with an example.

object = {
    somevariable: true,
    someothervariable:31,
    somefunction: function(input){
        if (somevariable === true){
            return someothervariable+input;
        }
    }
}

object.somefunction(3);

Obviously this won’t work. Do I have to say object.somevariable and object.someothervariable or is there a means of referring to variables that are part of the local object, without referring to the object explicitly?

Thanks

Gausie

  • 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-13T10:07:36+00:00Added an answer on May 13, 2026 at 10:07 am

    Use the special keyword this, which refers to the object a function was invoked on:

    var thing = {
        somevariable: true,
        someothervariable:31,
        somefunction: function(input){
            if (this.somevariable === true){
                return this.someothervariable+input;
            }
        }
    }
    thing.somefunction(3);
    
    var otherThing = {
        somevariable: true,
        someothervariable:'foo',
        amethod: thing.somefunction
    };
    otherThing.amethod('bar');
    

    Be careful about using variable names like “object”. JS is case-sensitive, so it won’t collide with the intrinsic Object, but you might get into trouble in other languages.

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

Sidebar

Related Questions

A quick question really.. Could someone explain why the first example would work, yet
Hey guys, one more quick question for any experts out there. I have a
Quick question: Which one is faster? foreach (Object obj in Collection) { if(obj.Mandatory){ ...
I am trying to start learning OO JS and have one quick question (i
just a quick question I have an array with only one object in it
I'm writing a simple program to convert text to strings. One quick question, how
Quick question. For example, working with a some-what larger case of ~1000 options: which
Quick question: One can set the path where a cookie is valid, but is
Quick question: One of my forms in my winform app (c#) makes an async
Quick question that requires a long explanation.. Say I have two tables - one

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.