Cuando intento ejecutar este script
window.onpopstate = function(popEvent) { let urlPath = window.location.pathName; let slash = page.lastIndexOf("/"); let page = urlPath.substr(slash+1); let $tab; if (page = '') { $tab = $("#tabs .tab:first-of-type"); page = $tab.attr("href"); } else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") } $tab.addClass("current").siblings().removeClass("current"); $.ajax({url: "subpages/"+page, function(html) { $(".append").html(html); } }); }Recibo el mensaje de error:
foo.js:38 Error de referencia no detectado: no se puede acceder a la 'página' antes de la inicialización en window.onpopstate (foo.js:38:15)
Realmente no entiendo cuál es el problema.
podria alguien ayudarme?
Este error fue causado solo por escribir mal: page → urlPath
window.onpopstate = function(popEvent) { let urlPath = window.location.pathName; let slash = urlPath.lastIndexOf("/"); // HERE let page = urlPath.substr(slash+1); let $tab; if (page = '') { $tab = $("#tabs .tab:first-of-type"); page = $tab.attr("href"); } else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") } $tab.addClass("current").siblings().removeClass("current"); $.ajax({url: "subpages/"+page, function(html) { $(".append").html(html); } }); }