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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:11:10+00:00 2026-06-15T20:11:10+00:00

I am trying to solve a problem that came to my mind lately. Let’s

  • 0

I am trying to solve a problem that came to my mind lately.
Let’s say we would want and would know how to make a point in having dynamic getters and setters in javascript, more like those in php (__get, __set). But as javascript does not have a catch-all property the only thing we could do is to provide a list of possible keys and iterate to add getters and setters on those only, and hope none other will ever come.

But the problem is not by far solved. So the next approach that came to my mind was to use a nasty hack with try and catch, so anytime a name would be undefined in an object to use the catch as a getter (at least) and then resume the code, hard and maybe pointless thing to do. But from here came my second problem, in an use such as this :

console.log(g.someundefinedproperty); 

the result would have been a call to console.log showing undefined with no exception to be ever thrown.
And then it came to me: what if I would use the original window.undefined getter and setter, after all it must be called every time I screw up and misspell a word or something.

So I tried

Object.defineProperty(window, 'undefined', {
    get : function ()
    {
         // functional code, including getting the caller and figuring out
         // where we are, and what we have to do... easy :D

         console.log('works');
    },
    set : function ()
    {
         // some couple more fine hacks here
         console.log('this too');
    }
});

But unfortunately the undefined property of window is configurable : false.
Other hacks tried were cloning the window object except the undefined and the inner window property. And on the new object to define the new undefined (please take note of the irony) and then window = mybetterwindow;

As this did not rose any issue my hopes were high, but yet again the system failed me as window can’t be overwritten, by design.
I made a guess it has it’s own getter and it’s reinstanciate itself based on the prototype found in window.prototype or even better Window.prototype (note the uppercase).

As my final step in this experiment I had redefined undefined on this prototype hitted run. To no avail, nothing was changed… I tryed creating a new Window(), but Window is not a constructor, fail!

As I have run out of ideas I find myself here writing this pleading for help.
If you have any ideas how to solve the dynamic getters and setters problem, (the existencial problem of life, universe and everything else), in a way which does not modify in any way the… way I use the objects (and as bonus it doesn’t need to break a hole in the fabric of time and space) or the syntax, I entreat you to speak or forever be silent :).

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

    But unfortunately the undefined property of window is configurable: false

    This is true only since EcmaScript 5.1. Before, it was overwritable.

    what if I would use the original window.undefined getter and setter, after all it must be called every time I screw up and misspell a word or something.

    No, it would not have worked. There is a difference between the undefined value and the global variable “undefined”. The variable is not evaluated each time a undefined value is encountered (e.g. in typeof (void 0)), only when you use it explicitly (such as in g.someprop === undefined).

    Any ideas how to solve the dynamic getters and setters problem?

    There is only one solution: Proxies. Unfortunately, it is only a harmony draft and currently only supported in Firefox’ Javascript 1.8.5.

    See also Is there an equivalent of the __noSuchMethod__ feature for properties, or a way to implement it in JS?, Detect when a new property is added to a Javascript object? or How to detect when a property is added to a JavaScript object? which implements a polling solution (checking for changes via setInterval).

    For a clean solution, you currently have to use an explicit getter function, which you pass the property name (g.get("someundefinedproperty")).

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

Sidebar

Related Questions

I'm trying to solve a problem that anonymous functions make much, much easier, and
I'm trying to solve the following problem in Redis. I have a list that
I am trying to solve this exponentiation problem . Here is the code that
This the problem in my book that I am trying to solve..I need to
Trying to solve this problem . I would like to learn how the bootstrapper
I was trying to Solve the Defense of a Kingdom problem and came up
I am trying to solve a problem that involves basically implementing a logical AND
The problem I'm trying to solve is to get all elements that contain only
I was trying to solve the maximal subsequence sum problem and came up with
I'm trying to solve Problem 13 of project euler, which involves the sum 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.