日期对象兼容斜杠
/**
* 源 Date
*/
const _Date_ = Date;
/**
* 修改第一个入参,横岗改斜杠
*/
Date = function () {
if (arguments.length > 0 && typeof (arguments[0]) === 'string' && arguments[0].includes('-')) arguments[0] = arguments[0].replace(/-/g, '/');
return new _Date_(...arguments);
}
/**
* 原型链
*/
Date.prototype = _Date_.prototype;
const oldDateStaticParam = Object.getOwnPropertyNames(_Date_);
const dateStaticParam = Object.getOwnPropertyNames(Date);
const diffParam = [];
for (let i = 0; i < oldDateStaticParam.length; i++) {
let find = false;
for (let j = 0; j < dateStaticParam.length; j++) {
if (oldDateStaticParam[i] === dateStaticParam[j]) {
find = true;
break;
}
}
if (!find) diffParam.push(oldDateStaticParam[i]);
}
for (let i = 0; i < diffParam.length; i++) Date[diffParam[i]] = _Date_[diffParam[i]];
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
CaptainTwo!
喜欢就支持一下吧