On 5 sep, 06:09, "Bruce Johnson" <[EMAIL PROTECTED]> wrote:
> I'm in favor of something much less designed. The extra object (i.e. the
> internal JSO) seems unnecessarily costly, considering that we're not trying
> to comply with an existing API such as the JRE Map interface.
> Why not avoid an abstract base class that necessitates polymorphism, adapter
> objects, etc., and instead use a JSO directly?

I suppose because you could cast any JSO to such a "map" and thus
break some assumptions?

@Emily: why not use hasOwnProperty for contains (rather than the "in"
operator)? (and an hasOwnProperty check within "for (k in map)" loops)
Of course this would mean that get() could return a non-null value
while contains() for the same key returns "false"...

> final class JsMapStringObject<V> extends JavaScriptObject {
>   public native V get(String k) /*-{ return this[k]; }-*/;
>   public native void put(String k, V v) /*-{ this[k] = v; }-*/;
>
> }
>
> This is admittedly less than full-featured and might need a little more (of
> course),

such as:
   public native boolean has(String k) /*-{ return
this.hasOwnProperty(k); }-*/
(could be "return (k in this)", or there might be both methods: has
and hasOwn)
and:
   public native void delete(String k) /*-{ delete this[k]; }-*/;

> but if the point is to do something special-purpose that's fast,
> then shouldn't we take it all the way?

+1 to include such a thing (btw, JsArray restricts values to JSOs, so
either JsMap needs the same restriction, or JsArray has to accept any
Object)

> In the same vein, we could also create:
>
> JsMapStringInt

I would call it JsMapInt, as "keys" in JavaScript are property names,
hence strings only.

> JsMapIntObject
> JsMapIntInt

Er, surely you mean JsArray and JsArrayInteger here? ;-)

(note that jso.cast<JsMap<V>>().get("1") would be strictly equivalent
to jso.cast<JsArray<V>>().get(1), as in JavaScript, array indices are
actually properties that can be evaluated as integers)



--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to