Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1740728.os95qiCnSi@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 27 Jan 2012 11:41:56 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit 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> <4f22011d$0$28325$862e30e2@ngroups.net> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 40 NNTP-Posting-Date: 27 Jan 2012 11:41:56 CET NNTP-Posting-Host: fcc0f6fb.newsspool2.arcor-online.net X-Trace: DXC=nYSLH8=L;Ad\^58DZm8W4\YJN 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 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