-
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 well -
ev._xandev._yare just variables pointing atev.offsetXandev.offsetYwhich are standard properties of the event object -
No idea what
layerXis supposed to be -
Since 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
solved Can’t understand this javascript code to paint HTML canvas? [closed]