Object copy
Mameri, Fred (HBO)
Fred.Mameri at hbo.com
Tue Jun 10 11:53:22 PDT 2014
And maybe there should be a Object.move for value types...
From: Frankie Bagnardi <f.bagnardi at gmail.com<mailto:f.bagnardi at gmail.com>>
Date: Tuesday, June 10, 2014 at 2:47 PM
To: Alex Kocharin <alex at kocharin.ru<mailto:alex at kocharin.ru>>
Cc: "es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>" <es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>>
Subject: Re: Object copy
I'd like Object.merge(source, dest), and Object.clone(source).
Object.clone would be best if it cloned almost any object, like more advanced clone functions. This includes plain objects, arrays, instances of classes (preserving base class, etc.), regExp, promise, and ideally DOM nodes in browsers (along with anything else that can be cloned). If something can't be cloned, including primitives and functions, it should throw an error.
Object.merge would be a much simpler "copy enumerable own properties" function.
Object.merge({a: 1}, {}); and Object.clone({a: 1}); would be equivalent, but they differ in most other cases.
On Tue, Jun 10, 2014 at 10:38 AM, Alex Kocharin <alex at kocharin.ru<mailto:alex at kocharin.ru>> wrote:
Object.create() ?
It's not exactly cloning, but it'll probably work better than cloning in most cases.
10.06.2014, 20:33, "Maxime Warnier" <marmax at gmail.com<mailto:marmax at gmail.com>>:
Hi All
Do you know if it is planned or maybe in discussion for ES7 to have a simple clone system on objects ?
There are different notations, from :
- jquery
Object.clone( [withDataAndEvents ] [, deepWithDataAndEvents ] )
( but only for DOM element )
- underscore
_.clone(object)
( return the cloned object )
- angular
angular.copy(source, [destination]);
(return the object, same as underscore, or copy into an optional destination )
Maybe an Object.copy([options?]) would be interesting ?
Maxime
Maxime Warnier
@maxdow
,
_______________________________________________
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
---------------------------------------------------------------------
This e-mail is intended only for the use of the addressees. Any copying, forwarding, printing or other use of this e-mail by persons other than the addressees is not authorized. This e-mail may contain information that is privileged, confidential and exempt from disclosure. If you are not the intended recipient, please notify us immediately by return e-mail (including the original message in your reply) and then delete and discard all copies of the e-mail.
Thank you.
---------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140610/059fea0a/attachment.html>
More information about the es-discuss
mailing list