Standardizing __proto__

Mike Shaver mike.shaver at gmail.com
Fri Mar 18 16:00:37 PDT 2011


On Fri, Mar 18, 2011 at 1:53 PM, John-David Dalton
<john.david.dalton at gmail.com> wrote:
> Ya, some people have that reaction at first, but after use it's not
> bad. Most of the time you create a string or value once then pass
> around the variable.
> Because these sandboxed natives chain, usage is natural. As such
> fuse.String(...).split(' ') produces a sandboxed Array so you go from
> 1 sandboxed native to another without hassle.
> Same goes for fuse.Array(1,2,3).join() -> a sandboxed String value.
>
> Generics are also supported fuse.String.concat(str, other) so you can
> pass in regular natives too.
>
> PrototypeJS and other libs use wrapper/utilities for strings, DOM
> elements, arrays, ... so using fuse.String() is just as easy as say
> $w().
> By using the framework it becomes second nature to assume, for
> example, fuse(...).getAttribute(..) returns a sandboxed String value.

But AIUI the point of sandboxing is to keep different libraries from
stepping on each other's toes, and AFAICT such libraries use literals
(string, array, object and regexp) quite liberally.  In Prototype all
4 are used.  In jQuery all 4 are used and passing in a String object
where a string primitive is expected will fail because of explicit
typeof checks.

If you *do* control the code in question, you can just write your code
to use a namespace (Object.prototype.ns.method(),
Object.prototype.ns2.method()) as easily as sprinkling |fuse.|
everywhere, and without giving up the ability to use literals or
closures (!).

Mike


More information about the es-discuss mailing list