Closed
Description
Follow-up to #525 (comment) — .bind
is slow and we should avoid it.
The code in question is here:
options._root._renderHooks.push( template.oncreate.bind( this ) );
We have a few options:
Go back to passing the context alongside the function
options._root._renderHooks.push({ fn: template.oncreate, context: this });
Not totally ideal, since a) you might not have a context, and b) if we were to include additional arguments (#550) then you'd have to deal with those too.
Wrap the function with a .call
var self = this;
options._root._renderHooks.push( function () {
template.oncreate.call( self );
});
Rewrite the function so that it takes the instance as an argument
var self = this;
options._root._renderHooks.push( function () {
template.oncreate( self );
});
I poked around a bit the other night and I don't actually think that's any faster than .call
, so probably not worth it.
I'm also not certain that wrapping the function is quicker than .bind
, we'd have to check. If not, then maybe we do need to consider going back to the old way of doing things.