Home >Web Front-end >JS Tutorial >{} and function(){} use empty objects {} to store keyValue_javascript techniques

{} and function(){} use empty objects {} to store keyValue_javascript techniques

WBOY
WBOYOriginal
2016-05-16 17:53:19913browse

If you try too hard, you will lose. I wrote a js tool class for manipulating URLs. This class has an attribute called queryString. My original approach was to let queryString=function(){}.

The idea is to be able to queryString Both writing methods [key] or queryString(key[,value]) are supported. Calling the key through queryString[key] is case-sensitive

and queryString(key) can be case-insensitive.

Today I found that the name parameter in the URL could not be set up. Suddenly I remembered that queryString is an anonymous function, and attributes such as name and length are read-only.

I changed it anyway. Into queryString = {}; Use another param(key[,value]) to implement the case-independent function.

I came to the conclusion today that it is best not to use function(){} to store keyValue in a field that already has built-in attributes.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn