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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:31:13+00:00 2026-06-08T23:31:13+00:00

File this one under just curious or is it possible? Say for example I

  • 0

File this one under “just curious” or “is it possible?”

Say for example I have…

home: function(options) {
   this._home('home', options)
}

login: function(options) {
    this._home('login', options)
}

home and login are obviously identifiers on dozens of object properties for tracking purposes. Is there a way to just return home or login without using any variables (an external function call is fine) within the object property?

UPDATE: Turns out this isn’t possible. The accepted answer doesn’t exactly answer the question, but it is a wonderful example of simplifying numerous calls to the same property.

  • 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-08T23:31:15+00:00Added an answer on June 8, 2026 at 11:31 pm

    If you mean that within the function that the home property references you want to be able to somehow get the string "home" from that property name without hardcoding it then no, to the best of my knowledge that isn’t possible.

    Just guessing at what you’re trying to achieve, would something like this help at least a little bit:

    function callHome(propName) {
       return function(options) {
          this._home(propName, options);
       }
    }
    
    var someObj = {
       home: callHome('home'),
       login: callHome('login')
    }
    someObj.home({some:"option"});
    

    At least then you don’t have to repeat the same function body for each property. Demo: http://jsfiddle.net/EeEAw/

    Note: I assume that the _home() function invoked but not defined in the question would be defined somewhere in the real-world code. I don’t show it in my answer, though I created a dummy one in my fiddle.

    Just as an aside, note that the function doesn’t really “belong” to the object or to the property – there’s nothing stopping you doing this sort of thing:

    var obj = {
       test : "test",
       home : function() {
          alert(this.test);
       }
    };
    var funcRef = obj.home;
    var obj2 = {
       method1 : funcRef
    }
    obj.home = null;
    funcRef();
    obj2.method1();
    

    That is, you can create multiple references to the same function, and the function will continue to exist even if the original obj.home property is set to some other value (as long as the additional references continue to exist).

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

Sidebar

Related Questions

I was just wondering if this is possible using TortoiseSVN: I have a file
if I have a text file like this : this is line one This
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
I have one binary file and I want to read this file like first
I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into
I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws
Banging my head on this one... I used tar -cvpzf file.tar.gz to compress a
I've seen this one-liner perl -lane '$_{$F[0]}+=$F[1]}print$_ $_{$_}for keys%_;{' file here: How can I
Man, stumped on this one. Trying to download a file with AFNetworking and the
This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50

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.