The original version was working fine in all browsers except IE.
I have replaced this with context in the return statement; otherwise, this was always pointing to window when the target function was being executed.