Hi David. Sure... I make a library that that needs to share a private variable with all methods of an instance passed by arguments on my lib' method.
``` var lib; (function () { var shared; shared = 'a shared value'; lib = { method: function method(foreignObject) { var property; for (property in foreignObject) { if (foreignObject.hasOwnProperty('property') { if (typeof foreignObject === 'function') { // how to pass the "shared" variable // preserving the inside this in foreignObject methods // and without to touch the methods args? } } } } }; }());``` The nearest way is something like this : ``` var foreignObject; foreignObject = { method: function method(shared) { console.log(shared); } }; lib.method(foreignObject); ``` And, in place of the lib.method comments : ``` foreignObject[property] = foreignObject[property].bind(foreignObject, shared); ``` It's really boring, because : - it don't works with non-writable methods, - it risks to loose the inside this of the methods (if not equal to foreignObject), - it forces to have a 'shared' arguments on each foreignObject method Better? :) Michaël Rouges - https://github.com/Lcfvs - @Lcfvs
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss