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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:12:41+00:00 2026-05-30T02:12:41+00:00

The context ( this ) is naturally the object that the property is being

  • 0

The context (this) is naturally the object that the property is being requested on, but there are no arguments passed to the getter function. I’d like to be able to get the name of the property being requested without using closures but it’s looking like that’s the only way to do it.

Object.defineProperty( someObj, "prop1", { get: genericGetter } );
Object.defineProperty( someObj, "prop2", { get: genericGetter } );

function genericGetter() {
    // i want to figure out whether this is called on prop1 or prop2
}
  • 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-30T02:12:41+00:00Added an answer on May 30, 2026 at 2:12 am

    Can I tell what property a generic getter/setter applies to in its
    body?

    That’s not how getters work. A property of an object can either have a value or a get function. If the property has a value, then reading the property:

    var x = obj.prop;
    

    returns that value. However, if a property has a get function instead, then reading that property triggers that function. So, you use getters if the value of a certain property has to be computed dynamically, or if you want to perform certain operations whenever the property is read.

    For instance, .innerHTML requires a getter, because its value is not stored statically, but computed on access:

    var html = div.innerHTML;
    

    Here, the browser has to serialize the DOM structure that is contained within the div element.

    So, if you want a .get() function that retrieves various properties (Backbone.js has such a function), then you’re not looking for getters.

    The simplest implementation of what you want would be:

    someObj.getProp = function ( name ) {
        // perform required tasks
        return this[ name ];
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The situation is this: You have a Hibernate context with an object graph that
In the context of this question link text is possible from a Controller that
This question has been asked in a C++ context but I'm curious about Java.
Context I came across some code, like this: if( Some_Condition ) throw 0; I
I have a question similar to this but in the context of L2S. I
For context - read this . Problem: class Program { static void Main() {
Is it bad practice to concatenate objects when used in this context: $this->template->head .=
I want to open a file for reading. However, in the context of this
This is in the context of Automatic Differentiation - what would such a system
Update: Please read this question in the context of design principles, elegance, expression of

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.