On Sat, Mar 19, 2011 at 7:41 PM, Andrew Dupont <[email protected]> wrote:
>
> Or, to use another example: let's say `MyObj` was defined in a different
> scope, one in which `clone` was assumed to be a public name. Can I do this...
>
> private clone = installCloneLibrary();
> var twin = [{a:0}, {b:1}].clone();
> var thing = MyObj.clone();
>
> ... and have it work the way I intend? In other words, once ES5 fails to find
> something with the `clone` private name defined on `MyObj`, will it try to
> find the property with the _public_ name of `clone` before it gives up? (If
> I'm reading this right, it won't.)
You're correct -- this won't do what you probably intended. But the
great thing about private names is that this is a problem you can
*locally* fix. For example:
private myClone = installCloneLibrary();
var twin = [{a:0}, {b:1}].myClone();
var thing = MyObj.clone();
or
var cloneProp = installCloneLibrary();
var twin = [{a:0}, {b:1}][cloneProp]();
var thing = MyObj.clone();
will both do what you expect, without requiring changes to either
CloneLibrary or MyObj. --
sam th
[email protected]
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss