W3C home > Mailing lists > Public > whatwg@whatwg.org > December 2009

[whatwg] Canvas.cloneNode()

From: Ian Hickson <ian@hixie.ch>
Date: Thu, 10 Dec 2009 15:38:32 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0912101537580.16061@hixie.dreamhostps.com>
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

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:54 UTC