1
我將window.location
保存爲一個變量,但當window.location
發生更改(History.js)時,我的變量也發生了變化,爲什麼?除了首頁請求之外,我不在任何地方設置變量。爲什麼我的保存的變量從window.location更改?
(function(){
var myvar = window.location;
History.Adapter.bind(window, 'statechange', function(){
console.log(window.location.pathname);
console.log(myvar.pathname); // same as window.location.pathname but should be saved data from line 2
var state = History.getState(),
options = {
url: state.url,
type: 'get',
success: function(resp, status, xhr) {
$('#wrapper').html(resp);
}
};
$.extend(options, callbackOptions);
$.ajax(options);
});
$(document).on('click', 'a[data-pjax]', function(e){
e.preventDefault();
var self = $(this),
callback = self.attr('data-pjax');
History.pushState({ "callback" : callback }, 'Loading page...', self.attr('href'));
});
})();
我加載頁面和我目前的location.pathname
是/foo
,我點擊一個pjax鏈接,我的新的URL /bar
。當我這樣做時,爲什麼myvar
被更改?我沒有更改變量的代碼。