Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

2.0.0b5 Thorax.Router.route() => Uncaught TypeError: Cannot call method 'apply' of undefined #66

Closed
ckrueger opened this issue Dec 16, 2012 · 3 comments
Assignees

Comments

@ckrueger
Copy link

Hi,

I'm currently evaluating a few MV* frameworks to use for a bigger project and so far I really like Thorax so naturally I was messing around with it and trying to create the TodoMVC example step-by-step on my own.
After implementing the router I got the following error:
Uncaught TypeError: Cannot call method 'apply' of undefined (thorax.js:1916)

Using the debugger it turns out that the callback argument in the route() function is undefined.
Digging deeper into the code I think I found the problem which is causing this error.

In Backbone.js (using the latest v0.9.9 in my learning project) the callback argument was omitted from the internal this.route() call (see: jashkenas/backbone@ef8e10f) because this argument is set in the route() function if it's not defined:

route: function(route, name, callback) {
    if (!_.isRegExp(route)) route = this._routeToRegExp(route);
    if (!callback) callback = this[name];
    // [...]

So I just took this line and added it to the beginning of the route() function in thorax.js:

route: function(route, name, callback) {
    if (!callback) callback = this[name];
    //add a route:before event that is fired before the callback is called
    return Backbone.Router.prototype.route.call(this, route, name, function() {
        this.trigger.apply(this, ['route:before', name].concat(Array.prototype.slice.call(arguments)));
        return callback.apply(this, arguments);
});

This did the trick and the router is now working.
Can you verify that this is the solution or am I actually missing something else? :)

Cheers, Chris

@ghost ghost assigned eastridge Dec 17, 2012
@eastridge
Copy link
Contributor

@ckrueger thanks for the detailed report on this one. We'll be releasing a new beta that is compatible with 0.9.9 this week and I'll make sure this fix gets in.

@eastridge
Copy link
Contributor

@ckrueger closing this as we are opening up a branch for all Backbone 0.9.9 issues. Thanks again for the detail on this one.

@ckrueger
Copy link
Author

👍
Sure no problem! Glad I could help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants