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


Groups > comp.lang.javascript > #32801

Re: Save instance of array "undo" and copy it back to array.

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Save instance of array "undo" and copy it back to array.
Date 2017-03-18 15:01 +0100
Organization PointedEars Software (PES)
Message-ID <1968884.iZASKD2KPV@PointedEars.de> (permalink)
References <358e280c-4521-42fe-abcb-6926efa129c4@googlegroups.com> <5y5t1y7xyqf0$.1g6m6w8017g2$.dlg@40tude.net>

Show all headers | View raw


JJ wrote:

> On Fri, 17 Mar 2017 02:00:39 -0700 (PDT), jonas.thornvall@gmail.com wrote:
>> If not, how would one go on calculate it?
> 
> It depends on what type of values are stored in each array element.

Most certainly not.  The values referred by array elements are most 
certainly _not_ part of the memory required for storing the array.  An 
efficient implementation would store pointers in the array only. 
 
> - Boolean type only need one byte but is rounded up to either 32-bit or
> 64-bit integer [1].

No, it depends on the implementation of ECMAScript.
 
> - Number type is a 64-bit floating point number.

At minimum, to satisfy IEEE 754 requirements.
 
> - String type is either a 32-bit or 64-bit integer [1] which is a memory
> pointer pointing to the actual UTF-8 string data. i.e. it has two data:
> pointer & text.

Again, that depends on the implementation.
 
> - Date type is […]
> - Object and Array types are […]
> - Function type is […]

See above.

> […] a structure array […]

Another figment of your vivid imagination.

> depending on the JavaScript engine.

Not “JavaScript engine”, but _implementation of ECMAScript_.  The various 
languages whose name contains “JavaScript” are _not_ the only 
implementations of ECMAScript.

You have been told this before ad nauseam.  Will you *ever* learn?
 
> In your example code, the operation would be the assignment of the array
> element.

Which is _not_ a “variable assignment”, but a property-write access.

> Since undoing a variable assignment requires you to know the
> original variable value, you'll need to store the original value before
> the variable assignment is actually performed. I'd recommend using the
> `Object.watch()` to do this.

Even your half-knowledge is out of date.  Object.*prototype*.watch() is 
proprietary (implementation-dependent, precisely SpiderMonkey-only), 
intended for *debugging*, and is deprecated (in favor of getters/setters 
and/or Proxy, I presume).

Object.observe(), which you might have meant instead, is proprietary, and 
deprecated in favor of getters/setters and/or Proxy, too.

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch> pp.

-- 
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 | Find similar | Unroll thread


Thread

Save instance of array "undo" and copy it back to array. jonas.thornvall@gmail.com - 2017-03-17 02:00 -0700
  Re: Save instance of array "undo" and copy it back to array. JJ <jj4public@vfemail.net> - 2017-03-18 18:53 +0700
    Re: Save instance of array "undo" and copy it back to array. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-03-18 15:01 +0100

csiph-web