
This is created every time your function is called. This could also speed up your code by a lot if used correctly.įor more on why it's bad practice, think about it this way: if you need to do some specific checking on an element after you've found it before you are ready to give it to the function, how are you supposed to pass that prepared element to the function?ĭon't let the function worry about how to get what it needs just give it what it needs.įetch me the context! Now throw it away! var ctx = canvas.getContext('2d') Instead, you should pass the DOM element itself. Your drawGrid function takes the id of a DOM element that the function is expected to find on its own. Quill already did a good job speeding up your code, so I'll focus on the code you have right now.
