[whatwg] Canvas.cloneNode()

On Thu, 10 Dec 2009, Michael A. Puls II wrote:
> 
> I don't know canvas stuff that well. What's the proper way to patch cloneNode
> to do a full copy?
> 
> I think something like the following, but maybe you know better.
> 
> (function() {
>     var oldCloneNode = HTMLCanvasElement.prototype.cloneNode;
>     HTMLCanvasElement.prototype.cloneNode = function(deep) {
>         var copy = oldCloneNode.call(this, deep);
>         var copy_ctx = copy.getContext("2d");
>         copy_ctx.drawImage(this, 0, 0, this.width, this.height);
>         return copy;
>     };
> })();

Looks right to me, though generally I would discourage this style of 
programming as it makes it quite hard for people to maintain unless they 
are very familiar with the codebase.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Thursday, 10 December 2009 07:38:32 UTC