Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35275

Re: Recording changes to an object

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.39.234.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Recording changes to an object
Date Fri, 22 Jun 2018 02:55:22 +0200
Organization PointedEars Software (PES)
Lines 61
Message-ID <1643274.5VXe1CXSyS@PointedEars.de> (permalink)
References <aYCdnU3Tes0_oLbGnZ2dnUU7-LHNnZ2d@westnet.com.au> <1620852.VI2in3QvqR@PointedEars.de> <Wcidne3I2Pl2qLHGnZ2dnUU7-XPNnZ2d@westnet.com.au>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
Injection-Info gwaiyur.mb-net.net; posting-host="39.234.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch:178.197.234.39"; logging-data="32561"; mail-complaints-to="abuse@open-news-network.org"
User-Agent KNode/4.14.2
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-User-ID U2FsdGVkX19Im/h1dcvZvvioKwZ+sOCFca8JdeTS1y7PQYeJha+3Yw==
Cancel-Lock sha1:nG2H3hZMpZZOxkMAyvmthx4J6y4=
Xref csiph.com comp.lang.javascript:35275

Show key headers only | View raw


Andrew Poulos wrote:

> On 22/06/2018 5:03 AM, Thomas 'PointedEars' Lahn wrote:
>> Property changes should only be possible via setter.  You can either make
>> the  actual properties private and have a getter that returns their
>> actual value –
> 
> [nice code clipped]
> 
> Great thanks, it looks an implementation of the same idea as Julio's.
> And it looks like it's something I can implement without too much pain.
> I just need to go through the dozens of places that the object is
> currently changed and implement the getter/setter.

Depending on what you mean by that, you might not be aware that even if you 
cannot use Proxy you may not have to implement the getter/setter in multiple 
places:

  /* code that defines o */

  function proxify (target, propertyNames)
  {
    propertyNames.forEach(function (name) { 
      var _p = this[name];

      /*
      Object.defineProperty(this, name, {
        "get": function () {
          return _p;
        },
        "set": function (value) {
          // …
          _p = value;
          // …
        }
      });
    }, target);
  }

  proxify(o, [propertyName1, propertyName2]);

  /* code that uses o */

Note that by having a top-level setter you can make sure that sub-level 
properties also use a setter: just convert the assigned value, if it is a 
reference to an object, to a reference to a object whose relevant properties 
have setters.

You can do the same with Proxy, but there also for yet unknown properties; 
also, only with Proxy you can trap deletion of properties.

Note also that getters and setters have been supported in some 
implementation before Object.defineProperty(), with 
Object.prototype.__defineGetter__() and Object.prototype.__defineSetter__(), 
which you can use as a fallback in Object.defineProperty() polyfill (as I do 
in JSX:object.js).

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-21 15:54 +1000
  Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 01:47 -0700
  Re: Recording changes to an object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-06-21 17:01 +0100
    Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 09:48 -0700
      Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 09:58 +0100
  Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-21 21:03 +0200
    Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 16:25 -0700
    Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-22 09:34 +1000
      Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:02 -0700
        Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 18:03 -0700
        Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 10:06 +0100
          Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 02:21 -0700
            Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 18:31 +0100
              Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 20:16 -0700
      Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 02:23 +0200
        Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:31 -0700
      Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 02:55 +0200
        Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-22 12:37 +1000
          Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 02:23 -0700
            Re: Recording changes to an object Jake Jarvis <pig_in_shoes@yahoo.com> - 2018-06-22 14:35 +0200
              Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 05:57 -0700
                Re: Recording changes to an object Mickey Finn <mfinn@gmail.com> - 2018-06-22 15:43 -0300
              Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 13:51 +0200
                Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 06:04 -0700
                Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 18:33 +0100
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-24 14:36 +0200
                Re: Recording changes to an object "Mark-" <nospam@mapson.xyz> - 2018-06-24 13:56 +0000
                Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-25 10:06 +0100
                Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:40 -0700
                Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:47 -0700
                Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:51 -0700
                Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:54 -0700
                Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:58 -0700
                Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-25 19:26 +0100
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-30 19:47 +0200
                Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-01 10:56 +0100
            Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-23 17:19 +1000
              Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-23 00:51 -0700
                Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-23 11:27 +0100
                Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-23 20:59 +1000
                Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-23 05:51 -0700
    Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-30 19:43 +0200
      Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-01 15:22 +0200
        Re: Recording changes to an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-02 16:29 +0200
          Cloning an object (was: Recording changes to an object) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-04 23:25 +0200
            Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 10:00 +0200
              Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 19:49 +0200
                Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 20:37 +0200
                Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 23:35 +0200
                Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 23:54 +0200
                Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 00:32 +0200
                Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 00:24 +0200
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-06 18:48 +0100
                Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 23:51 +0200
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-07 15:51 +0100
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-07 08:39 -0700
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 10:20 +0100
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:35 -0700
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:41 -0700
                Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 12:20 +0200
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-08 14:38 +0100
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:10 -0700
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 09:48 +0100
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:28 -0700
                Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:38 -0700
                Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 19:11 +0100
      Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-02 21:01 -0700
        Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 00:32 +0200
          Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-04 19:23 -0700
            Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 06:38 +0200
              Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-04 23:21 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 09:25 +0200
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-05 07:44 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 19:35 +0200
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-06 12:59 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 23:22 +0200
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-07 12:45 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 11:13 +0200
                Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 05:03 -0700
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-08 13:42 -0700
                Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:46 -0700
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-08 13:41 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-09 00:35 +0200
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-10 01:03 -0700
                Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-10 20:50 +0200
                Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-10 16:09 -0700
  Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-06-21 15:09 -0700
    Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 16:30 -0700
      Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-06-21 16:57 -0700
        Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:01 -0700

csiph-web