Вот как-то так получилось:
Function.prototype.callAsync = function() {
var self = this, args = $A(arguments), thisObj = args.shift(), elem = document.createElement('div'), done = false;
elem.onclick = function() {
if (!done) {
done = true;
self.apply(thisObj, args);
}
};
if (document.createEvent) {
var e = document.createEvent('HTMLEvents');
e.initEvent('click', false, false);
elem.dispatchEvent(e);
} else document.createDocumentFragment().appendChild(elem).fireEvent('onclick', document.createEventObject());
if (!done) setTimeout(elem.onclick, 15);
};
var $A = function(iterable) {
if (iterable) {
var result = [], i = iterable.length;
while (i) result[--i] = iterable[i];
return result;
}
return [];
};
var testFunc = function() {
alert('testFunc');
throw new Error('testFunc');
};
testFunc.method();
alert('global');
testFunc.method();
alert('global');