Event binding init fails if Object prototype is extended #684

wants to merge 1 commit into


None yet

4 participants


Inside the init function of the event binding handler the for loops over the event names in eventsToHandle, but it picks up extra functions from the object prototype and attempts to register as an event handler.

JQuery throws exception : Uncaught TypeError: [Method Code] has no method 'push'

jsFiddle to replicate : http://jsfiddle.net/slaneyrw/S6VaW/9/

Potential resolution: Need to check if the eventsTohandle "owns" the event name or if it comes from the prototype chain.

see discussion https://groups.google.com/forum/?fromgroups=#!topic/knockoutjs/ixlSf_qg1BE for more information


I agree that it would be best for us to use hasOwnProperty in this loop.


Added code and a spec to address this specific issue. Note: the spec will only fail with jQuery included.

There are other places where we are not using hasOwnProperty that could cause issues if Object.prototype is extended (css, style, attr bindings along with some other utility code). I will log another issue for us to evaluate.

mbest commented Nov 6, 2012

I'd prefer to have a utility function for this as suggested in #687.


Closing as a duplicate of #687 (though we can still refer back to this issue for details).

@mbest mbest deleted the 684-event-binding-loop-fix branch Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment