I have started creating an Undo script for the canvas element. It is far from complete, but the basics are in place. The code runs well in Chrome, Safari, and Opera yet throws errors in IE and Firefox. The error in Firefox is NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object and the error on IE is Invalid calling object.
Both errors are about the line that is: var original = context[p]; in the bind() function.
Here is my code: http://jsfiddle.net/evankennedy/cDdJd/
Some browsers don’t like it when you try to wrap methods of a native object in your own code. It’s a security “feature”.
You would be better off creating an entirely new object class that wraps the context and then proxies its methods (and properties).
This would also avoid the need for your
history.writestate since theundoandredomethods would still have access to the original methods.