Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!gegeweb.org!news.chainon-marquant.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <5478003.ScrLVSd4Jv@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 18 Oct 2011 11:12:40 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Objects comparaison ? Newsgroups: comp.lang.javascript References: <1k93ek2.1xghqcy1upjvv5N%unbewusst.sein@fai.invalid> <1783522.fYvYJRLvp5@PointedEars.de> <1411612.7OFYzboFZ6@PointedEars.de> <2326223.jLKWLtnpvF@PointedEars.de> <2065619.34vx2sxqLb@PointedEars.de> <2995463.SPkdTlGXAF@PointedEars.de> <2314707.NYtdq5378b@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 47 NNTP-Posting-Date: 18 Oct 2011 11:12:40 CEST NNTP-Posting-Host: ef52e659.newsspool1.arcor-online.net X-Trace: DXC=jbH0ZgUgS]4Fo<]lROoR1<`=YMgDjhg2D^`i3[QDZm8W4\YJN John G Harris schrieb: >> On Sun, 16 Oct 2011 at 21:59:39, in comp.lang.javascript, Thomas >> 'PointedEars' Lahn wrote: >>> Object.equals = function(obj1, obj2) {...} >> >> Attaching a global function (note it has two parameters) to Object is a >> very bad idea. > > Why that? I'd say it just belongs to there as other Object methods (like > keys() oder defineProperty(), see > https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object#Methods). The risk involved is that Object.equals() could be specified as a built-in later, maybe differently, and implemented. It might or might not be specified as read-only then, and if not, this would overwrite the built-in definition. Once specified and not implemented, however, such properties should be safe to be added like that, so that the efficiency of the native code can be leveraged without having to change the calling code. It requires the user- defined fallback to follow the Specification literally, though. > And what do you mean with "it has parameters"? Attaching a function > without parameters, or attaching a non-function property would be OK? He is confusing this with Object.prototype.equals(obj1, obj2), which would be a rather bad idea indeed, for two reasons: First, it would show up in for-in iteration as it would be enumerable (and it remains to be seen how widely Object.defineProperty() is implemented, so that this can be prevented). Second, the conflict between the `this' value and one of the arguments needs to be resolved: Which value refers to the object being compared against? (I would opt for the second argument to override the default `this' value, so that it can be optional. Cf. Array.prototype.filter(), e.g.) PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann