
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 0.46 KB | hits: 13 | expires: Never
How to set the receiver
foo = function(arg1,arg2){....};
arg1.foo(arg2);
var arg1 = {
foo: function(arg2) { }
};
arg1.foo(arg2)
var test = document.getElementById('test');
test.foo = function(arg) {
alert(this.innerHTML + " : " + arg);
};
test.foo("Hello");
function foo(arg1, arg2) {
if (typeof arg1 == 'function')
arg1(arg2); // or 'return arg1(arg2)' if necessary
else
return false;
}
foo(alert,'hello world');