outils
outils copied to clipboard
判断是否有传参为何需要先判断url==null
function parseQueryString(url) { url = url == null ? window.location.href : url var search = url.substring(url.lastIndexOf('?') + 1) if (!search) { return {} } return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}') } 以上这个方法为什么不直接写出url = url || window.location.href? 这样做是有什么好处吗?
两个作用一样
url = url || window.location.href,也没有问题,
url == null ? window.location.href : url,这样是为了只判断url为undefined或null的情况,排除一些其他类型的情况。
我想太多了。。。