outils icon indicating copy to clipboard operation
outils copied to clipboard

判断是否有传参为何需要先判断url==null

Open ceerqingting opened this issue 8 years ago • 3 comments

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? 这样做是有什么好处吗?

ceerqingting avatar Nov 16 '17 14:11 ceerqingting

两个作用一样

NaturelLee avatar Nov 17 '17 04:11 NaturelLee

url = url || window.location.href,也没有问题, url == null ? window.location.href : url,这样是为了只判断urlundefinednull的情况,排除一些其他类型的情况。

proYang avatar Nov 17 '17 04:11 proYang

我想太多了。。。

ceerqingting avatar Nov 17 '17 06:11 ceerqingting