javascript - Add function to context of canvas -


i'm working on creating libraries math in javascript, , 1 of grapher in canvas. i'm aiming this.

ctx.graph('sin(x)'); 

or that. how add method ctx of canvas? 1 other thing considering

graph(ctx,'sin(x)'); 

and using eval it.

thanks.

you extend prototype of context object include graph.

put code in .js file , include file projects:

var canvasplusgraph=document.createelement("canvas"); var contextplusgraph=canvasplusgraph.getcontext("2d");  object.getprototypeof(contextplusgraph).graph=function(...) {      // graph code } 

Comments