Comment #3 on issue 1038 by [email protected]: Wrong This object in
function called from Object::SetCallAsFunctionHandler
http://code.google.com/p/v8/issues/detail?id=1038
Olivier here is a pure JS solution:
function makeSignal() {
var handlers = [];
var signal = function () {
handlers.forEach(function (handler) { handler.call(this); }, this);
};
signal.connect = function (handler) { handlers.push(handler); };
return signal;
}
function Widget(name) {
this.name = name;
this.signal = makeSignal();
}
var w1 = new Widget("w1");
var w2 = new Widget("w2");
w1.signal.connect(function () { print(this.name); });
w2.signal.connect(function () { print(this.name); });
w1.signal();
w2.signal();
I think it can easily adopter for the case when you have C++ side attached
to the object/signal.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev