Re: Object copy

2014-06-11 Thread Maxime Warnier
Thanks for your answers.

Object.assign seems good but provides only copy for enumerable
properties, not a real deep clone.

I know for jquery, that's why i precised only for DOM but it was
just to show the syntax :)

2014-06-11 0:00 GMT+02:00 Rick Waldron waldron.r...@gmail.com:



 On Tue, Jun 10, 2014 at 12:32 PM, Maxime Warnier mar...@gmail.com wrote:

 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 ] )


 jQuery doesn't clone objects, it clones DOM elements.

 Rick



-- 
Maxime
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-11 Thread David Bruant

Hi Maxime,

Good to see you here :-)

This topic has been discussed recently on Twitter. See
https://twitter.com/jeremyckahn/status/474259042005553154

I'm like Rick's answer in particular
https://twitter.com/rwaldron/status/475017360085364736
as I believe a large share of cloning is just about data

As discussed in this Twitter thread, immutable data structures would be 
an interesting idea too. If an object is guaranteed to be deeply 
immutable, then, it can be passed around without the need for cloning. 
Clones are only necessary because the initial object is mutable in the 
first place.

Immutable data structures have been briefly discussed here recently:
https://mail.mozilla.org/pipermail/es-discuss/2014-June/037429.html
(see replies too)

David

Le 11/06/2014 08:49, Maxime Warnier a écrit :

Thanks for your answers.

Object.assign seems good but provides only copy for enumerable
properties, not a real deep clone.

I know for jquery, that's why i precised only for DOM but it was
just to show the syntax :)

2014-06-11 0:00 GMT+02:00 Rick Waldron waldron.r...@gmail.com:



On Tue, Jun 10, 2014 at 12:32 PM, Maxime Warnier mar...@gmail.com wrote:

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 ] )


jQuery doesn't clone objects, it clones DOM elements.

Rick





___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-11 Thread Maxime Warnier
Hi David :)

thanks for the links !

You are right, it's generally about data. Serialize an object to JSON
prevent from sharing references. On the twitter feed Jeremy talks
about optimizing the process . I'm agree with that, for performance
and a nicer syntax.

By the way, the Object.deepFreeze is really interesting , especially
for an API and when you want to set some private properties . But I
think it is a workaround to the issue of cloning because you can't
freeze all objects and maybe you want to have a mutable object but
cloning it afterward.

2014-06-11 9:58 GMT+02:00 David Bruant bruan...@gmail.com:
 Hi Maxime,

 Good to see you here :-)

 This topic has been discussed recently on Twitter. See
 https://twitter.com/jeremyckahn/status/474259042005553154

 I'm like Rick's answer in particular
 https://twitter.com/rwaldron/status/475017360085364736
 as I believe a large share of cloning is just about data

 As discussed in this Twitter thread, immutable data structures would be an
 interesting idea too. If an object is guaranteed to be deeply immutable,
 then, it can be passed around without the need for cloning. Clones are only
 necessary because the initial object is mutable in the first place.
 Immutable data structures have been briefly discussed here recently:
 https://mail.mozilla.org/pipermail/es-discuss/2014-June/037429.html
 (see replies too)

 David

 Le 11/06/2014 08:49, Maxime Warnier a écrit :

 Thanks for your answers.

 Object.assign seems good but provides only copy for enumerable
 properties, not a real deep clone.

 I know for jquery, that's why i precised only for DOM but it was
 just to show the syntax :)

 2014-06-11 0:00 GMT+02:00 Rick Waldron waldron.r...@gmail.com:



 On Tue, Jun 10, 2014 at 12:32 PM, Maxime Warnier mar...@gmail.com
 wrote:

 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 ] )


 jQuery doesn't clone objects, it clones DOM elements.

 Rick







-- 
Maxime WARNIER
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-11 Thread Rick Waldron
On Wednesday, June 11, 2014, Maxime Warnier mar...@gmail.com wrote:

 Thanks for your answers.

 Object.assign seems good but provides only copy for enumerable
 properties, not a real deep clone.

 I know for jquery, that's why i precised only for DOM but it was
 just to show the syntax :)


Oops, sorry, I overlooked that.

Rick


 2014-06-11 0:00 GMT+02:00 Rick Waldron waldron.r...@gmail.com
 javascript:;:
 
 
 
  On Tue, Jun 10, 2014 at 12:32 PM, Maxime Warnier mar...@gmail.com
 javascript:; wrote:
 
  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 ] )
 
 
  jQuery doesn't clone objects, it clones DOM elements.
 
  Rick



 --
 Maxime

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Object copy

2014-06-10 Thread Maxime Warnier
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@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-10 Thread Alex Kocharin
 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" mar...@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 listes-discuss@mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-10 Thread Mameri, Fred (HBO)
And maybe there should be a Object.move for value types...

From: Frankie Bagnardi f.bagna...@gmail.commailto:f.bagna...@gmail.com
Date: Tuesday, June 10, 2014 at 2:47 PM
To: Alex Kocharin a...@kocharin.rumailto:a...@kocharin.ru
Cc: es-discuss@mozilla.orgmailto:es-discuss@mozilla.org 
es-discuss@mozilla.orgmailto:es-discuss@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 
a...@kocharin.rumailto:a...@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 mar...@gmail.commailto:mar...@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@mozilla.orgmailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.orgmailto:es-discuss@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.

-

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-10 Thread C. Scott Ananian
On Tue, Jun 10, 2014 at 2:47 PM, Frankie Bagnardi f.bagna...@gmail.com wrote:
 I'd like Object.merge(source, dest), and Object.clone(source).

`Object.assign` is already in the ES6 spec.
 --scott
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Object copy

2014-06-10 Thread Rick Waldron
On Tue, Jun 10, 2014 at 12:32 PM, Maxime Warnier mar...@gmail.com wrote:

 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 ] )


jQuery doesn't clone objects, it clones DOM elements.

Rick
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss