[TOC]
## 3 [\core\util\] 基礎工具目錄
### 3-1 目錄文件
### 3-2 (index.js)入口文件
>[export]
~~~
;(導出)工具接口
export * from 'shared/util'
export * from './lang'
export * from './env'
export * from './options'
export * from './debug'
export * from './props'
export { defineReactive } from '../observer/index'
~~~
### 3-3 (lang.js)語言擴展工具
>[info] module
~~~
;字符串是否以$或_開頭
export function isReserved (str) {
const c = (str + '').charCodeAt(0)
return c === 0x24 || c === 0x5F
}
;對象屬性定義
export function def (obj, key, val, enumerable) {
Object.defineProperty(obj, key, {
value: val,
enumerable: !!enumerable,
writable: true,
configurable: true
})
}
;路徑解析
const bailRE = /[^\w\.]/
export function parsePath (path) {
if (bailRE.test(path)) {
return
} else {
path = path.split('.')
return function (obj) {
for (let i = 0; i < path.length; i++) {
if (!obj) return
obj = obj[path[i]]
}
return obj
}
}
}
~~~
>[info] export
~~~
;(導出)檢查字符串是否以$或_開頭
export function isReserved (str) {}
;(導出)定義對象的一個屬性
export function def (obj, key, val, enumerable){}
;(導出)點路徑解析
export function parsePath (path) {}
~~~
### 7-4 (env.js)環境工具
>[info] module
~~~
;檢查簡單對象是否有__proto__屬性
export const hasProto = '__proto__' in {}
;檢查是否瀏覽器運行環境
export const inBrowser =
typeof window !== 'undefined' &&
Object.prototype.toString.call(window) !== '[object Object]'
;開發工具
export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
;瀏覽器客戶端類型
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
const isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
const isWechat = UA && UA.indexOf('micromessenger') > 0
;異步運行
export const nextTick = (function () {
let callbacks = []
let pending = false
let timerFunc
;異步調用接口
function nextTickHandler () {
pending = false
const copies = callbacks.slice(0)
callbacks = []
for (let i = 0; i < copies.length; i++) {
copies[i]()
}
}
;生成異步執行函數timerFunc
if (typeof MutationObserver !== 'undefined' && !(isWechat && isIos)) {
let counter = 1
const observer = new MutationObserver(nextTickHandler)
const textNode = document.createTextNode(counter)
observer.observe(textNode, {
characterData: true
})
timerFunc = function () {
counter = (counter + 1) % 2
textNode.data = counter
}
} else {
const context = inBrowser
? window
: typeof global !== 'undefined' ? global : {}
timerFunc = context.setImmediate || setTimeout
}
;返回異步執行函數
return function (cb, ctx) {
const func = ctx
? function () { cb.call(ctx) }
: cb
callbacks.push(func)
if (pending) return
pending = true
timerFunc(nextTickHandler, 0)
}
})()
;環境表的添加,檢查,清空操作
let _Set
if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
_Set = Set
} else {
_Set = function () {
this.set = Object.create(null)
}
_Set.prototype.has = function (key) {
return this.set[key] !== undefined
}
_Set.prototype.add = function (key) {
this.set[key] = 1
}
_Set.prototype.clear = function () {
this.set = Object.create(null)
}
}
;導出環境表接口
export { _Set }
~~~
>[info] export
~~~
;(導出)是否可以使用__proto__
export const hasProto
;(導出)是否瀏覽器運行環境
export const inBrowser
;(導出)開發環境工具
export const devtools
;(導出)異步執行
export nextTick{}
;(導出)環境集合
export { _Set }
~~~
### 3-5 (options.js)
### 3-6 (debug.js)
### 3-6 (props.js)
### 3-7 (defineReactive)

- 概述
- 框架結構
- 編譯入口(\entries)
- web-compiler.js(web編譯)
- web-runtime.js(web運行時)
- web-runtime-wih-compiler.js(web編譯運行)
- web-server-renderer.js(web服務器渲染)
- 核心實現 (\core)
- index.js(核心入口)
- config.js(核心配置)
- core\util(核心工具)
- core\observer(雙向綁定)
- core\vdom(虛擬DOM)
- core\global-api(核心api)
- core\instance(核心實例)
- 模板編譯(\compiler)
- compiler\parser(模板解析)
- events.js(事件解析)
- helper.js(解析助手)
- directives\ref.js(ref指令)
- optimizer.js(解析優化)
- codegen.js(渲染生成)
- index.js(模板編譯入口)
- web渲染(\platforms\web)
- compiler(web編譯目錄)
- runtime(web運行時目錄)
- server(web服務器目錄)
- util(web工具目錄)
- 服務器渲染(\server)
- render-stream.js(流式渲染)
- render.js(服務器渲染函數)
- create-renderer.js(創建渲染接口)
- 框架流程
- Vue初始化
- Vue視圖數據綁定
- Vue數據變化刷新
- Vue視圖操作刷新
- 框架工具
- 基礎工具(\shared)
- 模板編譯助手
- 核心實例工具
- Web渲染工具
- 基礎原理
- dom
- string
- array
- function
- object
- es6
- 模塊(Module)
- 類(Class)
- 函數(箭頭)
- 字符串(擴展)
- 代理接口(Proxy)
- 數據綁定基礎
- 數據綁定實現
- mvvm簡單實現
- mvvm簡單使用
- vdom算法
- vdom實現
- vue源碼分析資料