Closed taburetkin closed 5 years ago
The documentation gives you two method signatures to choose from:
(name, callback, [context]) => this
({name: callback}, [context]) => this
You are doing something that matches neither signature:
({name: callback}, context, context, context) => ?
so you are violating the preconditions of the method. This is also called breaking the contract. In general, you cannot expect a piece of software to do what it is supposed to do if you break the contract.
I do agree the result is a bit surprising. Purely out of academical interest, I had a look in the annotated source to see what's going on. It appears that the implementation of Events.on
relies first and foremost on the number of arguments. If you pass a third argument (b
in your case), the implementation concludes you must be invoking the first signature of the method, so that third argument must be the context.
Hi there. I believe it's not an issue but rather a question
the docs says:
i have this example: https://codepen.io/dimatabu/pen/zXgQjE
the console output is:
{b:1}, 1, 2, 3
and i want to understand • what happens witha
andc
arguments when i bind a handler in such way ? • it seems thatb
is not last argument as noticed in docs, the last one isc
, so docs are a little bit incorrect? • what for this at all? (because there is even a test for that, but suddenly its not clear from test why this should be like that)edit: i can understand if the output will be
{a:1}, 1, 2, 3
or{c:1}, 1, 2, 3
the last one actually not clear for me, but at least it corresponds the docs.and the last one with this registration:
Backbone.on('a', handler, a, b, c);
output will be{a:1}, 1, 2, 3
, why there is a difference between string and hash handler registration?with regards.