I have code that is trying to track the current fragment in a Backbone js application.
$(function(){ Backbone.history.start({pushState: true}); console.log("fragment " + Backbone.history.fragment);
This code prints the "snippet xxx" as expected, but always prints the "snippet from the undefined event handler" when I navigate in the application.
If I copy Backbone.History to a local var, it works first:
$(function(){ Backbone.history.start({pushState: true}); console.log("fragment " + Backbone.history.fragment); var hist = Backbone.history; Beef.router.bind("all", function(route) { console.log("fragment from event handler " + hist.fragment); }); });
Can someone explain what is going on here?
source share