I'm noticing that I have this line of code repeated in many different places in my code:
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
First, I'm wondering the performance implications of this. For example, in my redrawing code which is called very often, I do that. Similarly, I may use JQuery to get a reference to the element.
I was wondering how big of a deal this was. I'm not exactly sure how to properly profile a website. I would like to somehow create a global reference to the context but when I try to do it in the global scope it doesn't run. Is the only way to have a function that lazily returns a reference to the canvas?