What about making the Path2D constructor a property of each context? E.g. var path = new myContext.Path2D(...); Each context would have a different constructor tied to it, allowing this kind of optimization.