On Mon, Sep 18, 2017 at 6:13 PM, Zach Bjornson wrote:
>> `myObj.onevent()` invokes `onevent()` with `this === myObj`. Unless
>> you want to deviate significantly from normal JS semantics, you would
>> need to maintain a reference to `myObj` anyway.
>
>
> (The spec I'm emulating actually states th
>
> `myObj.onevent()` invokes `onevent()` with `this === myObj`. Unless
> you want to deviate significantly from normal JS semantics, you would
> need to maintain a reference to `myObj` anyway.
>
(The spec I'm emulating actually states that `onevent()` is invoked with
the global context.) So
On Sat, Sep 16, 2017 at 3:17 AM, Zach Bjornson wrote:
> Hello,
>
> I'm trying to implement this type of interface:
>
> var myObj = new MyObj();
> myObj.onevent = function () {
> // might be a reference to myObj here
> }
> myObj.doSomethingAsync(); // causes `onevent` to fire; can be called more
No, storing a weak reference on the object itself won't work.
Maybe a map of Persistent, not associated with the MyObj instances,
but keyed on the MyObj instance? SetOnevent stores to that map; firing an event
involves a lookup; MyObj's destructor deletes from the map?
Thanks,
Zach
--
--
v8-
Hello,
I'm trying to implement this type of interface:
var myObj = new MyObj();
myObj.onevent = function () {
// might be a reference to myObj here
}
myObj.doSomethingAsync(); // causes `onevent` to fire; can be called more
than once
`onevent` (a C++ setter) currently stores the callback func