[ad_1]
Pencil is a class. In JavaScript, class constructors take the form of
function MyClass()thisis used to point to the class itself, from within the constructor or member functions. Thus,this.mouseup()can be accessed from an instance (in your case) astool.mouseup()Because that’s the variable your class uses to keep track of the movement. If you want to replace
tool, you have to replace thetool.startedassignments and evaluations as wellev._xandev._yare just variables pointing atev.offsetXandev.offsetYwhich are standard properties of the event objectNo idea what
layerXis supposed to beSince the same function is called on all the events (
mousedown,mousemove,mouseup), the last function just figures out which event was triggered and calls the appropriate function within your pencil instance (tool).
3
[ad_2]
solved Can’t understand this javascript code to paint HTML canvas? [closed]