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, 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.



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



安装: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 });