Closed slavafomin closed 9 years ago
Hey Slava,
It might be adequate for you to do something like the following:
if (Cookies.get('foo')) {
// ...
}
The only practical difference between this and checking that a value is not undefined
, is that an empty string value would also evaluate as false
. This is usually an insignificant difference, however.
Hey! Thanks for suggestion.
However, I do believe that loose type conversion will always have some weak points. Introducing a has
method will provide a robust and convenient way to check the existence of the cookie. I think it's practically a "must have" for any collection interface in programming.
Hey Slava,
If you can provide me with a common, legitimate, real world scenario where loose type conversion presents a problem, then I will consider adding a has
method. I'm not particularly interested in extending the API of the library just because it seems like a specific feature is practically a "must have". Instead, I am much more interested in providing a pragmatic interface that is shaped to actual needs.
It seems to me that in the overwhelming majority of cases, loose type conversion will not be problematic. As a result, it seems excessive to bloat the library with another method that will likely only need to be used very rarely, if ever.
Hello!
I would propose to add a
has
method to simplify testing for cookie existence.So we can write:
if (Cookies.has('foo')) { ... }
instead ofif ('undefined' !== typeof Cookies.get('foo')) { ... }
.Thanks!