[TOC]
******
## 1 Class的意義
1. js語言傳統方法通過構造函數,定義生成新對象,
~~~
function Point(x,y){
this.x = x;
this.y = y;
}
Point.prototype.toString = function () {
return '(' + this.x + ', ' + this.y + ')';
}
~~~
2. ES6提供了Class語法糖,來簡化對象的創建。通過Class關鍵字,可以定義類。
~~~
//定義類
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
~~~
3. ES6的類,完全可以看做構造函數的另一種寫法
~~~
;類的數據類型是函數,類本身指向構造函數
class Point{
// ...
}
typeof Point // "function"
Point === Point.prototype.constructor // true
;構造函數的prototype屬性,在ES6的類上面繼續存在。類的所有方法都定義在類的prototype屬性上面
class Point {
constructor(){
// ...
}
toString(){
// ...
}
toValue(){
// ...
}
}
// 等同于
Point.prototype = {
toString(){},
toValue(){}
}
;在類的實例上調用方法,其實就是調用原型上的方法
class B {}
let b = new B();
b.constructor === B.prototype.constructor // true
;類的方法都定義在prototype屬性上面,類的新方法可以添加在prototype上面。Object.assign可以很方便一次向類添加多個方法,而prototype對象的constructor屬性,直接指向類的本身。類的內部定義的所有方法,都是不可枚舉的,這一點與ES5的行為不一致。
~~~
class Point {
constructor(){
// ...
}
}
Object.assign(Point.prototype, {
toString(){},
toValue(){}
})
Point.prototype.constructor === Point // true
class Point {
constructor(x, y) {
// ...
}
toString() {
// ...
}
}
Object.keys(Point.prototype)
// []
Object.getOwnPropertyNames(Point.prototype)
// ["constructor","toString"]
~~~
## 2 constructor方法
1. constructor方法是類的默認方法,通過new命令生成對象實例時,自動調用該方法,一個類必須有constructor方法,沒有顯示定義,空的constructor方法會被默認添加
## 3 創建實例對象
## 4 Class的繼承
## 5
- 概述
- 框架結構
- 編譯入口(\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源碼分析資料