On Fri, Jul 25, 2014 at 1:35 PM, Rick Waldron <[email protected]> wrote:
> On Fri, Jul 25, 2014 at 4:29 PM, Tab Atkins Jr. <[email protected]>
> wrote:
>> Ah, so you've got a "private" variable (declared in a closure) that
>> you want to share with other objects which aren't created in the same
>> closure.
>>
>> This is what Symbols/WeakMaps were made for.
>
> I'd be interested to see what your approach would be—afaict, this would
> require exposing the Symbol or WeakMap to whatever scope the foreign object
> is defined in and then there's no point in using either.
Yeah, upon actually walking through my desired example, I found that
the Symbol/Weakmap is irrelevant. Here's what I was thinking, using
only existing stuff:
```
(function(){
var shared1;
function ForeignObject() { /* Uses shared1 somehow */ }
ForeignObject.setSharedSecret(val) {
shared1 = val;
}
})();
(function(){
var shared2 = "the real secret";
function MyObject() { /*...*/ }
MyObject.exposeSharedSecret(cb) {
cb(shared2);
}
})();
MyObject.exposeSharedSecret(ForeignObject.setSharedSecret);
```
~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss