[PROPOSAL] "use" keyword

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Jul 25 13:34:18 PDT 2014


forgot to fix one of many typos in your initial example too ... `if
(foreignObject.hasOwnProperty(property)) {` ...


On Fri, Jul 25, 2014 at 1:33 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> the method knows shared as soon as you define it inside your closure ...
>
>
> ```
> var lib;
>
> (function () {
>     var shared;
>
>     shared = 'a shared value';
>
>     function wrap(method) {
>       return function () {
>         var args = [].slice.call(arguments);
>         args[0] = shared;
>         return method.aply(this, args);
>       };
>     }
>
>     lib = {
>         method: function method(foreignObject) {
>             var property;
>
>             for (property in foreignObject) {
>                 if (foreignObject.hasOwnProperty('property')) {
>                     if (typeof foreignObject[property] === 'function') {
>                         foreignObject[property]
> = wrap(foreignObject[property]);
>                     }
>                 }
>             }
>         }
>     };
> }());
>
> ```
>
> ... take care ...
>
>
>
> On Fri, Jul 25, 2014 at 1:25 PM, Michaël Rouges <michael.rouges at gmail.com>
> wrote:
>
>> @Andrea :
>>
>> Yeah, I don't really want to rewrite the methods, I only want to share my
>> "shared" variable with these methods.
>>
>> Furthermore, your code don't works because "method" don't knows "shared".
>>
>>
>>
>> Michaël Rouges - https://github.com/Lcfvs - @Lcfvs
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140725/6f755eee/attachment-0001.html>


More information about the es-discuss mailing list