11 comments

[ 2.2 ms ] story [ 40.6 ms ] thread
Is it reliable to add methods to a built-in object like CanvasRenderingContext2D? I avoid it, but perhaps just out of superstition.
If you know what you are doing it's fine, but it might cause incompatibility issues from namespace collisions.

You can rearrange the code to accept a context as the first argument if you are worried.

nice we need more lessons like this.
Nice work. Very interesting. Canvas is such a fun API.
Do you mind if I add these to my own library? https://github.com/Lerc/whio (MIT Licence)

It's a library I use when I teach kids JavaScript. It provides simple global functions to let them get started before they have to deal with ideas such as canvas context objects.

A Wiki page showing the functions they get to use is at http://fingswotidun.com/code/index.php/API

The functions you show here are exactly the sort of thing that would be useful for beginners.