this指向?

this is set according to how the method is called, and not according to how the method is written. So for obj.method(), this will be set to obj inside of method(). For obj.method.call(x), this inside of method() will be set to x. It is determined by how it’s called. What that also means is that if you pass it as a callback to e.g. onclick, this will be set to the global window object rather than what you expect.

参考1:https://stackoverflow.com/questions/13224620/the-this-keyword-returns-the-window-object-within-an-objects-prototype-in-jav

参考2:https://segmentfault.com/a/1190000008400124

JavaScript 函数中的 this 指向并不是在函数定义的时候确定的,而是在调用的时候确定的。换句话说,函数的调用方式决定了 this 指向

继续阅读this指向?

js-cookie设置有效期,天/时/分/秒

https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions

安装:npm i js-cookie

const expires;

expires = 7; // 7天

expires = 0.5 // 半天(12h)

expires = 1/48; // 30分钟

expires = new Date(new Date().getTime() + 15 * 60 * 1000); // 15分钟

expires = new Date(new Date().getTime() + 60 * 1000); // 60秒

Cookies.set(name, value, { expires: expires });