Skip to content

@kirbysayshi /message.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function m(object, message, options) {
if (!object || !message || typeof (message) !== 'string') {
return null;
}
if (object === null || typeof (object) !== 'object') {
return null;
}
var reponse = null;
/* If the object doesn't respond to the message but defines behavior for
* forwarding, recursively forward the message */
if (typeof (object[message]) === 'undefined' && typeof (object['forwardInvocation']) !== 'undefined') {
response = m(object.forwardInvocation(), message, options);
} else if (typeof (object[message]) === 'function') {
response = object[message](options);
}
return response;
}
function class1() {
this.forwardInvocation = function () {
return object2;
};
}
function class2() {
this.forwardInvocation = function () {
return object3;
};
}
function class3() {
this.receivingFunction = function () {
return 'Message received.'
};
}
var object1 = new class1();
var object2 = new class2();
var object3 = new class3();
alert(m(object1, 'receivingFunction'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.