Skip to main content

vue-next-shared

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 响应系统追踪变化,提升性能。

列表渲染性能

Vue2 官方文档

String.prototype.startsWith()#

ES6 新增字符串方法

Object.is()#

值得注意的是
+0 === -0; // trueNaN === NaN; // falseObject.is(NaN, NaN); // trueObject.is(+0, -0); // false

记录#

NOOP 空函数#

使用场景

  1. 方便判断
  2. 方便压缩

正则表达式#

isOn()
const onRE = /^on[^a-z]/;const isOn = (key: string) => onRE.test(key); // true or false

globalThis#

let _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/