Object.equals() and Object.clone()

Domenic Denicola d at domenic.me
Tue Nov 15 04:55:13 UTC 2016


The biggest problem with structured clone is that there’s no way to just invoke it directly. Doing so has been proposed a few times, most recently at https://github.com/whatwg/html/issues/793, but no implementers have expressed interest.

From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Kevin Barabash
Sent: Monday, November 14, 2016 23:51
To: Eric Devine <devineej at gmail.com>
Cc: es-discuss <es-discuss at mozilla.org>
Subject: Re: Object.equals() and Object.clone()

I didn't know about structured clone so I looked it up.  It looks pretty promising.  As for checking if two things are equal, maybe it makes sense for objects to define their own `.equals(other)` methods.

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm

On Mon, Nov 14, 2016 at 9:31 PM, Eric Devine <devineej at gmail.com<mailto:devineej at gmail.com>> wrote:
How about beginning with the HTML structured clone algorithm, and a `Symbol.clone` property to allow an object to optionally define it's own cloning behavior?

On Mon, Nov 14, 2016 at 9:02 PM, Isiah Meadows <isiahmeadows at gmail.com<mailto:isiahmeadows at gmail.com>> wrote:
I agree. Also, consider iterables. Should their `Symbol.iterator` method be called? There's no obvious behavior for the details, and people's opinions differ on what should be correct.

On Mon, Nov 14, 2016, 20:58 Frankie Bagnardi <f.bagnardi at gmail.com<mailto:f.bagnardi at gmail.com>> wrote:
It's pretty hard to decide how these behave, specifically with custom classes. Focusing on Object.clone...

- with classes do you call the constructor, and with what arguments?
- HTMLElement and sub classes can't be constructed directly, what happens with them?
- do you copy internal properties? this would make it hard to polyfill
- how does it behave with getters and setters?
- with regular expressions do you copy the lastIndex?

Most of those apply to Object.equals also.



On Mon, Nov 14, 2016 at 6:25 PM, Kevin Barabash <kevinb at khanacademy.org<mailto:kevinb at khanacademy.org>> wrote:
It would be nice if deep equality checking and deep cloning of objects was included in the standard library.  Has there been any proposals around including these in the past?

– Kevin


_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161115/4394eadd/attachment.html>


More information about the es-discuss mailing list