ES6 類的輸入輸出

2021-08-01 04:34:04 字數 1199 閱讀 5983

var name = 'xiaochun'

var age = '22'

export name

//引用

import name from

'../test.js'

var name = 'xiaochun'

var age = '22'

export

//引用

import from

'../test.js'

**

輸出

export function

getname

() export function

getage

()

輸入

import * as test from

"../test.js"

test.getname() //getname123

test.getage() //getage456

//module也可以達到整體輸入

module test from

"../test.js"

test.getage() //getage456

**

乙個模組只能使用 export default 一次

//輸出

export default

function

getage

()//輸入

import test from '../test.js'

test() //123

//或者

//輸出

function

getname

()export default getname

//輸入

import test from '../test.js'

test() //456

//同時輸出de****st 和變數物件

//輸出

export default getname

export

//輸入

import de****tmethod, from

'../test.js'

es6 類的繼承

function animal name animal.prototype.drink function animal.prototype.eat function item function dog name,breed animal.prototype dog.prototype animal....

ES6 類的繼承

類的繼承 super 關鍵字 子類通過 extends 關鍵字來繼承父類的所有屬性和方法 子類必須在constructor中呼叫super方法,否則新建例項會報錯 es5的繼承中,實質是先創造子類的例項物件this,然後再將父類的方法 屬性新增到this上面。es6的繼承中,實質是先創造父類的例項物...

ES6類的繼承

es6 引入了關鍵字class來定義乙個類,constructor是構造方法,this代表例項物件。constructor相當於python的init而this則相當於self 類之間通過extends繼承,繼承父類的所有屬性和方法。super關鍵字,它代指父類的this物件,子類必須在constr...