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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:52:26+00:00 2026-06-01T20:52:26+00:00

I wish to extend the Object and Array classes so that I will be

  • 0

I wish to extend the Object and Array classes so that I will be able to listen to any changes made to their instances after construction.

The best I can do now is to add custom get and set functions for fields given at initialization/construction of an Instance:

var myObj = new CustomObject({name:'foo'});

myObj.name = 'bar'; // this will log "'name' in 'myObj' updated:'bar'"

//however:

myObj.age = 85; // this mutation will slip by unnoticed, 
                // since the 'age' field was never specified 
                // at initialization meaning no custom set / get 
                // functions where attached.

Is there a way to achieve the following functionality?

var myObj = new CustomObject();

myObj.name = 'foo';// this should log something like:
                   // "A new field 'name' was created for myObj with value 'foo'"

Note:I’m looking for a solution that doesn’t involve polling.

What I have now (resulting in the functionality shown in the first codeblock):

function CustomObject(data) {

    var that = this;

    for(var field in data){         
        prepField(field);                                   
    }

    function prepField(field){                  
        Object.defineProperty( that, field, {
            set: function(val){         
                data[field] = val;
                console.log(field,'in',that,'updated:',val);
            },
            get: function(){
                console.log(field,'in',that,'requested');
                return data[field];                 
            },
            enumerable:true
        });         
    }

    return this;

}

Thanks in advance!

  • 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-01T20:52:28+00:00Added an answer on June 1, 2026 at 8:52 pm

    Firefox (mozilla) has something called Proxy that can do this.

    MDN Proxy docs

    This is a non-standard feature currently, but appears as though it (or something similar) may become part of ECMAScript 6.

    From http://wiki.ecmascript.org/doku.php?id=harmony:proposals :

    enter image description here

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

Sidebar

Related Questions

I wish to add a singleton method to a particular object. I wish that
I'm using an API that has an abstract class that I wish to extend
i've inherited a project that is using subsonic. I wish to extend the OrderItem
when creating an object I wish to extend the functionality of an existent prototype
I wish to have a single class which all of my Activity classes extend.
I wish to be able to generate URL variables like this: http://example.com/195yq http://example.com/195yp http://example.com/195yg
I wish to get a list of all strings that are used in a
I asked this question on SO. However, I wish to extend it further. I
I have a byte array wich i wish to add as an attachement to
I'm looking to build a pipeline pattern with Scala. I wish after I write

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.