BadMutable
Day.js 被设计为不可变的,但是,为了使其与一些旧项目中的 moment.js 完全兼容,我们引入了一个插件 🚨 BadMutable 🚨 来使 Day.js 可变。
¥Day.js is designed to be immutable, however, in order to make it fully compatible with moment.js in some legacy projects we introduced a plugin 🚨 BadMutable 🚨 to make Day.js mutable.
This is NOT 很好,不推荐用于大多数项目。
¥good and NOT recommended for most projects.
启用此插件后,所有设置器都将更新实例本身。
¥With this plugin enabled, all setters will update the instance itself.
var badMutable = require("dayjs/plugin/badMutable");
// import badMutable from 'dayjs/plugin/badMutable' // ES 2015
dayjs.extend(badMutable);
// with 🚨 BadMutable 🚨 plugin
const today = dayjs();
today.add(1, "day");
console.log(today); // update itself, value will be tomorrow