ScottHamper / Cookies

JavaScript Client-Side Cookie Manipulation Library
The Unlicense
1.77k stars 169 forks source link

better way to set Cookies.default #61

Closed AnthonyACE closed 8 years ago

AnthonyACE commented 8 years ago

I meet the Cookies.expire doesn't work problem, cause by wrong way to set Cookies.default. My stupid way is that, Cookies.default = { expires: 3600 }. That stupid mistake will make the Cookies.default.path change to undefined, which will cause Cookies.set('key') set the cookie at current path. Then when you use Cookies.expire('key') will not expire the Cookie key in the current path. You can still get the cookie by Cookie.get('key').

If someone meet the problem that Cookies.expire doesn't work as you wish. Maybe you set the Cookies.default with the stupid way , just like me

So, which way is the better way to set Cookies.default.

  1. do the assign outside. Cookies.default = assign({}, Cookies.default, { expires: 3600 }).
  2. do the assign inside cookie-js. Maybe will need a func setDefault, Cookies.setDefault({ expires: 3600 }).just like some other Project . eg: i18next, i18next.init({yourSetting}).
ScottHamper commented 8 years ago

Hey @AnthonyACE ,

You can do the following to set the expires parameter without overriding other settings:

Cookies.defaults.expires = 3600;

AnthonyACE commented 8 years ago

Thx a lot