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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:09:10+00:00 2026-06-03T03:09:10+00:00

For example, here’s my Hello machine: hello_machine = new HelloMachine; At this point, if

  • 0

For example, here’s my “Hello” machine:

hello_machine = new HelloMachine;

At this point, if someone tries to access a property in hello_machine, I’d like the following to happen.

hello_machine.fred;
hello_machine.greetings(); // output: Hi, fred!

hello_machine.george;
hello_machine.greetings(); // output: Hi, george!

I’d like this to happen automatically, regardless of the property they are trying to access. I don’t want anything hard-coded.

This is the function that I would like called:

function set_buddy(name) {
  buddy = name;
}

And greetings would be the following:

function greetings() {
  alert('Hi, ' + buddy);
}

The obvious solution is to not do this. It’s terrible practice and it changes a very fundamental way Javascript behaves. However, I’m in a position where this type of behavior would be fantastic to have.

My gut tells me that this isn’t possible, and the internet has not been able to dissuade me of that fact (my head tells me I’m a fool for asking). But I know that Javascript is a fickle mistress and it would not surprise me if this functionality existed. Therefore, if anyone knows of any hack I can implement to get this behavior, I would surely appreciate it.

  • 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-03T03:09:11+00:00Added an answer on June 3, 2026 at 3:09 am

    Sadly, you cannot do this without proxies: http://soft.vub.ac.be/~tvcutsem/proxies/

    Which aren’t widely supported at all yet. Not even close.

    If the properties you wish to invoke were known before hand, you could declare getter methods with Object.define_property which is a bit more widely supported. But without knowing the properties to be invoked ahead of time, there is no way to intercept them without proxies.

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

Sidebar

Related Questions

The fictional example here. Suppose I designed a class named IODevice. This class already
You can see the example here: http://jsfiddle.net/8EHED/8/ This is a tricky problem because I
Example here: http://jsfiddle.net/7h2Dh/ Got this html: <span>Text<div id=wtf>Content</div>Text</span> I need to set div display
i have this simple example here : http://jsfiddle.net/pTyvc/1/ i don't want the sub_menu div
The example here doesn't make sense, but this is basically how I wrote my
I'm following the example here: jMock - getting started I'm getting this error: The
I looked into the example here C-like structures in Python But The example is
i am trying to follow this example here : http://www.sencha.com/forum/showthread.php?11735-How-can-I-ADD-to-baseParams-rather-than-overwrite-one-set-of-baseParams-with-another The objective is to
I'm following this example here: http://erikonrails.snowedin.net/?p=230 I added: lib/delayed_job_spec_helper.rb Then in my rspec I
I found a great example here of how to do this in xaml, but

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.