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
Maybe a map of Persistent<Function>, 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
`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.
var myObj = new MyObj();
myObj.onevent = function () { // (a C++ setter)
console.log(myObj); // reference to myObj here
}
myObj.doSomethingAsync(); // causes `onevent` to fire eventually
class MyObj : ObjectWrap {
Persistent<Function> _onevent;
void setOnEvent(Local<String> prop, const PropertyCallbackInfo<Value>& info); // stores fn arg in _onevent
}