This little snippet from that wiki page looks like it should be helpful.

function bind(object, boundMethodName) {
  if (object.hasOwnProperty(boundMethodName)) {
    return object[boundMethodName];
  }
  var boundMethod = object[boundMethodName].bind(object);
  Object.defineProperty(object, boundMethodName, {
    value: boundMethod
  });
  return boundMethod;
}

I don't know the internals of the emitter, but if you can detect
specifically when a function member is accessed (and not simply called),
you'd be able to use this function there. I like that it would ensure that
binding a function only happens on demand. That's better than binding every
member function up front. All other functions that aren't being used as
event listeners or passed to a variable can be accessed from the prototype
chain normally.

- Josh


On Thu, Jul 16, 2015 at 2:21 AM, Frank Wienberg <fr...@jangaroo.net> wrote:

> Hi guys,
> honestly I didn't read through the whole thread, but just wanted to remind
> you of what we collected about binding methods in the Apache Flex Wiki:
>
> https://cwiki.apache.org/confluence/display/FLEX/Simulating+AS3+language+features+in+JavaScript+using+AMD+and+ES5#SimulatingAS3languagefeaturesinJavaScriptusingAMDandES5-Boundmethods
> Maybe it helps / clarifies things!
>
> Cheers
> -Frank-
>
> On Wed, Jul 15, 2015 at 1:18 PM, Michael Schmalle <
> teotigraphix...@gmail.com
> > wrote:
>
> > On Tue, Jul 14, 2015 at 7:11 PM, Alex Harui <aha...@adobe.com> wrote:
> >
> > > Bummer.
> > >
> > > Did you try:
> > >
> > >   this.addEventListener("mousedown", simpleButton_mousedownHandler);
> > >
> > > The “this.” might be creating a pattern that isn’t handled.  I’m sort
> of
> > > hoping Mike will finish his mother-in-law’s bathroom and find time to
> > > start in on some way to pass context so we don’t have to one-off these
> > > patterns.
> > >
> >
> > I'm done as of last Friday but my wife keeps inventing more things for me
> > to do around the house, like buying 4 pieces of trim for the doors and
> > baseboard.
> >
> > I am VERY short on time right now as it's summer and the kids are home,
> > blah blah. :) Plus I still need to keep working on my AIR projects for my
> > fall goal.
> >
> > I guess, if you can create a new thread and clearly explain the problem
> and
> > solution I can then look at it with a clean slate and figure out how much
> > time it might take me to do given the current emitter's state.
> >
> > I know I did something with the other compiler and event listeners, I
> would
> > have to look.
> >
> > Mike
> >
> >
> >
> > >
> > > -Alex
> > >
> > > On 7/14/15, 3:50 PM, "Josh Tynjala" <joshtynj...@gmail.com> wrote:
> > >
> > > >Alex,
> > > >
> > > >The change you made worked for the case where the function is assigned
> > to
> > > >a
> > > >variable, but it doesn't account for the function being passed as an
> > > >argument to a function.
> > > >
> > > >This still doesn't work for me:
> > > >
> > > >this.addEventListener("mousedown",
> this.simpleButton_mousedownHandler);
> > > >
> > > >However, as a workaround, I can do this, for now:
> > > >
> > > >var mouseDownListener:Function = this.simpleButton_mousedownHandler;
> > > >this.addEventListener("mousedown", mouseDownListener);
> > > >
> > > >- Josh
> > > >
> > > >On Sun, Jun 28, 2015 at 10:13 PM, Alex Harui <aha...@adobe.com>
> wrote:
> > > >
> > > >>
> > > >>
> > > >> On 6/28/15, 2:21 PM, "Michael Schmalle" <teotigraphix...@gmail.com>
> > > >>wrote:
> > > >>
> > > >> >On Sun, Jun 28, 2015 at 5:17 PM, Josh Tynjala <
> joshtynj...@gmail.com
> > >
> > > >> >wrote:
> > > >> >
> > > >> >> Yes, that is correct.
> > > >> >>
> > > >> >> In case it wasn't obvious, event listeners are the typical use
> case
> > > >> >>where
> > > >> >> you'd pass a reference to a member function somewhere else where
> a
> > > >> >> reference needs to be saved in a variable. AS3 made this easy by
> > > >> >> automatically binding member functions. JavaScript usually
> requires
> > > >>some
> > > >> >> manual intervention to get event listeners to be called with the
> > > >>right
> > > >> >> scope.
> > > >> >>
> > > >> >
> > > >> >Yeah the compiler does this already for anonymous functions, it
> > > >>creates a
> > > >> >self var pointing to 'this' and then uses self in the anonymous
> > > >>function's
> > > >> >body.
> > > >>
> > > >> Actually, that ‘self’ stuff is for AS lexical scoping.  Josh is more
> > > >> interested in the use of goog.bind for function identifiers.
> FalconJX
> > > >> handles that correctly in most cases for addEventListener and other
> > > >> callbacks, but I guess we don’t handle this scenario.
> > > >>
> > > >> I can try to take a look at it, but if you want to, search for
> > > >>GOOG_BIND.
> > > >>
> > > >> >
> > > >> >I wasn't aware of this problem though, can you create a JIRA
> ticket?
> > I
> > > >> >probably will be the one that tackles it since I am sure Alex
> doesn't
> > > >>have
> > > >> >time to do something like this and test it as well.
> > > >>
> > > >> Well, I can probably get it working, but I’m sure I won’t test it as
> > > >>well
> > > >> as you will.
> > > >>
> > > >> -Alex
> > > >>
> > > >>
> > >
> > >
> >
>

Reply via email to