Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10637
| Message-ID | <1740728.os95qiCnSi@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-01-27 11:41 +0100 |
| Subject | Re: Comparing arraies |
| Newsgroups | comp.lang.javascript |
| References | <8dc6b834-cd20-47a5-a085-f4d5e4402c38@c13g2000yqk.googlegroups.com> <4f218d62$0$6578$9b4e6d93@newsspool3.arcor-online.net> <4f21dd07$0$28275$862e30e2@ngroups.net> <fir3i7heoeap4t42lkrvkbmnqjk69htr9i@4ax.com> <4f22011d$0$28325$862e30e2@ngroups.net> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Denis McMahon wrote:
> Gene Wirchenko wrote:
>> Denis McMahon wrote:
>>> […]
>>> function are_identical(var1, var2) {
>>> return JSON.stringify(var1) === JSON.stringify(var2); }
>>>
>>> I think this would work for anything that can be stringified by the
>>> JSON.stringify() method.
>>
>> Why not just toString()?
>> if (var1.toString()===var2.toString())
>
> var x;
> x.fred = 9;
> x.jim = 23.654;
> x.sue[0] = [15,"mouse",[12,14,5,"BASHER"],543.876];
> x.sue[1] = "is x.toString() defined?";
This code cannot run (as-is; if `x' was assigned a reference to an object
with a `sue' property before, then it *could* work), and does not constitute
a proof at all.
A useful example showing why toString() does not suffice for all cases is
/* "1,2,3,4" == "1,2,3,4" */
[1, [2, 3], 4].toString() == [[1, 2], [3, 4]].toString()
If the JSON property is unavailable or wrong implemented, it can be
emulated, either by using the implementation from <http://json.org/> or
another object serializer.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Comparing arraies Archos <raul.san@sent.com> - 2012-01-26 07:23 -0800
Re: Comparing arraies Martin Honnen <mahotrash@yahoo.de> - 2012-01-26 18:29 +0100
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-26 19:50 +0100
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-26 19:54 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-27 16:49 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-27 18:41 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-28 11:28 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 21:17 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-29 14:55 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 17:13 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-30 15:27 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-30 19:03 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-31 15:07 +0000
Re: Comparing arraies Dr J R Stockton <reply1205@merlyn.demon.co.uk> - 2012-01-31 18:51 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-30 12:01 -0800
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-31 11:06 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-31 06:08 -0800
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-01-31 16:08 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-31 18:32 -0800
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-02-01 17:02 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-01 10:07 -0800
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-02-02 15:10 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-02 11:16 -0800
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-02-07 15:14 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-01 21:45 +0100
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-01 13:07 -0800
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-01 23:44 +0100
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-01 18:22 -0800
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-02 23:09 +0100
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-03 01:47 +0100
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-02-04 10:34 +0000
Re: Comparing arraies Dr J R Stockton <reply1205@merlyn.demon.co.uk> - 2012-02-05 16:47 +0000
Re: Comparing arraies John G Harris <john@nospam.demon.co.uk> - 2012-02-06 15:21 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-04 23:37 -0800
Re: Comparing arraies Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-26 23:08 +0000
Re: Comparing arraies Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-27 01:42 +0000
Re: Comparing arraies Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-27 11:41 +0100
Re: Comparing arraies Gene Wirchenko <genew@ocis.net> - 2012-01-26 16:24 -0800
Re: Comparing arraies "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-27 08:50 +0000
Re: Comparing arraies Dr J R Stockton <reply1204@merlyn.demon.co.uk> - 2012-01-27 21:07 +0000
Re: Comparing arraies "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-28 13:45 +0000
Re: Comparing arraies "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-26 16:21 -0800
Re: Comparing arraies Martin Honnen <mahotrash@yahoo.de> - 2012-01-27 16:00 +0100
csiph-web