Simple Js Router
<p>Just to learn I created a simple javascript router to call my functions. This works great. My problem is coming from that I am using push/pop state to change through the urls. So in my code when it goes through a push/pop it activates the router and everything gets loaded but the old function for the old page is still loaded. This is causing conflicting javascript and problems. So my question is there a way to un call a function? Or erase it some how? Here is some of my basic code:</p>

<pre><code>addRoute('user/:username', function() {
    user.start();
});

addRoute('user/:username/:action', function() {
    user.start();
});

function addRoute(route, callback, action) {
    router.defined[route] = {
        callback : callback,
        action : action
     };
}

function listen(ifPoPState) {
    var routeInfo = match();

    if (typeof routeInfo == 'undefined') return false;

    routeInfo.callback();

    if (ifPoPState &amp;&amp; typeof routeInfo.action != 'undefined') {
        routeInfo.action();
    };

}

function match() {
    //awesome js to match the routes
}

function _push($el) {
    // awesome js to use pop/push state
}
</code></pre>
