Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ceerqingting opened this issue Nov 16, 2017 · 3 comments
Open

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

ceerqingting opened this issue Nov 16, 2017 · 3 comments
Labels

Comments

@ceerqingting
Copy link

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

@NaturelLee
Copy link

两个作用一样

@proYang
Copy link
Owner

proYang commented Nov 17, 2017

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

@ceerqingting
Copy link
Author

我想太多了。。。

@proYang proYang added the 建议 label Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants