vue-next-shared
shared: Internal utilities shared across multiple packages (especially environment-agnostic utils used by both runtime and compiler packages).
index.ts
文件主要是不同 packages 之间共享的工具函数,对 JavaScript API 进行封装以方便调用。
#
API#
Object.freeze()冻结对象,使对象不可更改。
使用Object.freeze()
阻止 Vue 响应系统追踪变化,提升性能。
#
String.prototype.startsWith()#
Object.is()值得注意的是
+0 === -0; // trueNaN === NaN; // falseObject.is(NaN, NaN); // trueObject.is(+0, -0); // false
#
记录#
NOOP 空函数使用场景
- 方便判断
- 方便压缩
#
正则表达式isOn()
const onRE = /^on[^a-z]/;const isOn = (key: string) => onRE.test(key); // true or false
#
globalThislet _globalThis: any;export const getGlobalThis = (): any => { return ( _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}) );};
#
参考#
拓展【JS 对象 API】 https://mp.weixin.qq.com/s/Y3nL3GPcxiqb3zK6pEuycg
【JS 正则迷你书】.老姚 https://github.com/qdlaoyao/js-regex-mini-book
【Promise 迷你书】http://liubin.org/promises-book/