Object copy

Frankie Bagnardi f.bagnardi at gmail.com
Tue Jun 10 11:47:18 PDT 2014


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> 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>:
>
> 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
> https://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> 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/20140610/3d5cad2d/attachment.html>


More information about the es-discuss mailing list