Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Recording changes to an object Date: Thu, 21 Jun 2018 17:01:58 +0100 Organization: A noiseless patient Spider Lines: 17 Message-ID: <87po0kruvd.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="9a7ffc44ba370fd369117882bf279116"; logging-data="13244"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iCMGP9X0374dcPcnNyUxrMkhoIHPM5Pc=" Cancel-Lock: sha1:ADrDHNs+M+q2Vt5T6+EzE884SJg= sha1:Hlo3HewrHMkIzwn3cMB/qDQ8Pzc= X-BSB-Auth: 1.d5d0434f991caf06a4ba.20180621170158BST.87po0kruvd.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:35262 Andrew Poulos writes: > Is their some approach I can follow to make a multiple level undo? > I need something that does: > > 1. Has the object has been changed? > 2. If, yes, what was the change eg obj['1'].a value changed from 1 to 2 > 3. When the user calls undo it finds the change and reverses it. I would consider storing the changes as a list of functions. When you make a change, you also make a change-reversing function. Depending on the structure of the code that makes the changes, the reversing function could be quite simple. -- Ben.