As an siginificantly simplified scenario, say I have 2 Javascript objects defined as below:
var ClassA = Class.extend({
'say': function(message) {
console.log(message);
}
... // some more methods ...
});
var ClassB = Class.extend({
init: function(obj) {
this._target = obj;
}
});
I'd suppose that in Javascript there is some kind of mechanism could enable us to do the following trick:
var b = new ClassB( new ClassA() );
b.say("hello");
I'd like to find a way to detect if there is a method called upon ClassB
, and the method is not defined in ClassB
, then I can automatically forward the method call to be upon ClassA
, which is a member variable in ClassB
.
In a realworld scenario, ClassA
is an object implemented as brwoser plugin and inserted into the webpage using <object>
tag. It's method is implemented in C++ code so there is no way I can tell its methods from its prototype and insert it to ClassB
's prototype beforehand.
I'd like to use the technical to create a native Javascript object, with a narraw-ed version of ClassA's interface. Is there a way I can do this?