I would think this would be easier:
public static final native JavaScriptObject deepCopy(JavaScriptObject
obj) /*-{
return eval('{'+JSON.stringify(obj)+'}');
}-*/;
I haven't tested the above code, but it should work.
On Apr 4, 8:51 pm, Dean Huffman <[email protected]> wrote:
> Since it took me 3 hours to figure out why this doesn't work and I
> could not find any other post on the subject, here is one way to do a
> deep copy of a JavaScriptObject using JSNI.
>
> public static final native JavaScriptObject deepCopy(JavaScriptObject
> obj) /*-{
> if (Object.prototype.toString.call(obj) === '[object Array]') {
> var out = [], i = 0, len = obj.length;
> for ( ; i < len; i++ ) {
> out[i] = arguments.callee(obj[i]);
> }
> return out;
> }
> if (typeof obj === 'object') {
> var out = {}, i;
> for ( i in obj ) {
> if (i != "__gwt_ObjectId") {
> out[i] = arguments.callee(obj[i]);
> }
> }
> return out;
> }
> return obj;
>
> }-*/;
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.