![思圖前端課程8-ecmascript_第1頁(yè)](http://file4.renrendoc.com/view/842a02b4b5312f3a8a27854bce0c8d00/842a02b4b5312f3a8a27854bce0c8d001.gif)
![思圖前端課程8-ecmascript_第2頁(yè)](http://file4.renrendoc.com/view/842a02b4b5312f3a8a27854bce0c8d00/842a02b4b5312f3a8a27854bce0c8d002.gif)
![思圖前端課程8-ecmascript_第3頁(yè)](http://file4.renrendoc.com/view/842a02b4b5312f3a8a27854bce0c8d00/842a02b4b5312f3a8a27854bce0c8d003.gif)
![思圖前端課程8-ecmascript_第4頁(yè)](http://file4.renrendoc.com/view/842a02b4b5312f3a8a27854bce0c8d00/842a02b4b5312f3a8a27854bce0c8d004.gif)
![思圖前端課程8-ecmascript_第5頁(yè)](http://file4.renrendoc.com/view/842a02b4b5312f3a8a27854bce0c8d00/842a02b4b5312f3a8a27854bce0c8d005.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、ES6 課程1 ES61-ES6 是什么ECMAScript6.0(以下簡(jiǎn)稱(chēng) ES6)是 JavaScript6JavaScriptES6 課程1 ES61-ES6 是什么ECMAScript6.0(以下簡(jiǎn)稱(chēng) ES6)是 JavaScript6JavaScript1-常用語(yǔ)Parameters(默認(rèn)參數(shù)) initerals(模板文本)inMulti-line Strings (多行字符串)in ES6 Destructuring Assignment (解構(gòu)賦值)in ES6 EnhancedObjectLiterals(增強(qiáng)的對(duì)象文本)inES6 Arrow Functions (箭頭函數(shù)
2、)in ES6PromisesinBlock-ScopedConstructsLetandConst(LetandConst) Classes(類(lèi)) in ES6Modules(模塊) in22-varname=while(true)var name = obama console.log(name) /obama console.log(name) letname=whileconsole.log(name) letname=while(true)let name = obama console.log(name) /obama console.log(name) vara=for(vari
3、=0;i10;i+) ai = function () a6();/vara=for(leti=0;i)varf=v=varES6 允許使用“箭頭”(=)varf=v=varf=function(v) return v;varf=()=varf=function()returnvarsum=(num1,num2)=varsum=function(num1,num2) return num1 + num2;+return(x,y)=x+;y-;returnfunction(x,yy-returnx+報(bào)letgetTempItem=id=id:id,name:Temp letgetTempItem
4、=id=(id:id,name:TempletgetTempItem=id=(id:id,name:Templetfn=(i,j)= constfull=,last)+functionfull( )+. class Animal this.type=console.log(this.type+says+say),varanimal=newanimal.says(hi) /undefinedsaysthisselfselfvar self = this; console.log(self.type+says+,console.log(self.type+says+,console.log(thi
5、s.type+says+say)class Animal this.type=setTimeout()=console.log(this.type+says+,var animal = new Animal() animal.says(hi) /animalsayshi當(dāng)thisthis2-模板字符串/變Thereare+basket.count+ items in your basket, +basket.onSale+ are on sale!上面這種寫(xiě)法相當(dāng)繁瑣不方便,+9Thereare$basket.countinyourbasket,$basket.onSale are on sa
6、le!模板字符串(ZKSVRGZK XO上面這種寫(xiě)法相當(dāng)繁瑣不方便,+9Thereare$basket.countinyourbasket,$basket.onSale are on sale!模板字符串(ZKSVRGZK XO)是增強(qiáng)版的字符串,用反引號(hào)(F)標(biāo)識(shí)。它可以當(dāng)普通字InJavaScriptnisaline-多行字Inthisisnot字符串中嵌入letname=Bob,time=o$name,howareyou換行。如果你不想要這個(gè)換行,可以使用 XOS 方法消除它 )GYY(類(lèi))的基本語(yǔ) IXOVZ 語(yǔ)言中,生成實(shí)例對(duì)象的傳統(tǒng)方法是通過(guò)構(gòu)造函數(shù)。下面是一個(gè)例子function
7、 Po(x,y) this.x = x;this.y=.prototype.toString=function()return(+this.x+,function Po(x,y) this.x = x;this.y=.prototype.toString=function()return(+this.x+,+this.y+varp=new(1,classES6classclassconstructor(x,y) this.x = x; this.y = y;toString()return(+this.x+,+this.y+的ES6classtypeof=class Bar doStuff()
8、varb=newBar(); prototypeES6class Bar doStuff()varb=newBar(); prototypeES6this對(duì)象上),否則都是定義在原型上(class上)。classtoString().prototype=toString()classBletb=newb.constructor=bclassprototypeconstructorES5ClassextendsES5classprototypeconstructorES5ClassextendsES5classclassextends類(lèi)classextendsconstructor(x,y,co
9、lor)super(x,y調(diào)用父類(lèi)的constructor(x,this.color=toString()returnthis.colorsuper.toString調(diào)用父類(lèi)的this對(duì)象。constructorsuperclass/*.*/classextendsletcp=new();/this上面(Parent.apply(this))。ES6letcp=new();/this上面(Parent.apply(this))。ES6classextendsclassextendsconstructor(.args) super之后,才可以使super方法才能返回父類(lèi)實(shí)例。classconst
10、ructor(x,y) this.x = x; this.y = y;classextendsconstructor(x,y,color)this.color=color;/ReferenceError super(x, y);this.colorcolor;正super方法之后就是正確的。letcp=new(25,8,cpinstanceof/cpinstanceof/和cpinstanceof/cpinstanceof/和ES5classAso()oclassBextendsAo() osupersuper函數(shù)。classAclassBextendsA constructor() 必須的,
11、否則 JavaScript 引擎會(huì)報(bào)錯(cuò)。classAclassBextendsA constructor() newA()/A newB()/newA()/A newB()/thisB。classAclassBextendsA m() super報(bào)classA p() returnclassBextendsA constructor() ();/letb=newsuper在普通方法之中,指向A.prototype,所以supsuper調(diào)用的。class A constructor()this.p=classBextendsA get m() returnletb=newclassBextend
12、sA get m() returnletb=newb.m/就classAA.prototype.x=classBextendsA constructor() console.log(super.x)/2letb=newclass A constructor()this.x=()classBextendsA constructor() this.x=2;m()rletb=newb.m()/letb=newb.m()/thisclass A constructor()this.x=classBextendsA constructor() this.x=2;super.x=console.log(s
13、uper.x);/undefined console.log(this.x); / 3letb=newclassAclassBextendsA constructor() console.log(super報(bào)錯(cuò)JavaScriptclassAclassBJavaScriptclassAclassBextendsA constructor() console.log(super.valueOf()instanceofB);/letb=newsuperBthissuper.valueOf()返回的是一個(gè)Bvar obj = toString()returnMyObject:+obj.toStrin
14、g();/MyObject:object2-Module(模塊)語(yǔ) 一直沒(méi)有模塊RubyrequireimportCSSimportJavaScriptES6CommonJSAMD前者用于服務(wù)器,后者用于瀏覽器。ES6而且實(shí)現(xiàn)得相當(dāng)簡(jiǎn)單,完全可以取代 CommonJS 和 AMD 規(guī)范,成為瀏覽器和服務(wù)ES6如,CommonJS 模塊就是對(duì)象,輸入時(shí)必須查找對(duì)象屬性。CommonJS模let,exists,readFile=let_fsES6如,CommonJS 模塊就是對(duì)象,輸入時(shí)必須查找對(duì)象屬性。CommonJS模let,exists,readFile=let_fs=let=;let ex
15、ists = _fs.exists; letreadfile=_fs.readfile;(_fsES6模import,exists,readFilefromES6ES6 JavaScript(macro)和類(lèi)型檢驗(yàn)(typesystem)這些只能UMDES6APIexport望外部能模JSexport/exportName=exportvarlastName=Jackson; export var year = 1958;exportName=exportvarlastName=Jackson; export var year = 1958;/Name=varlastName=varyear=
16、exportName,lastName,exportfunctionmultiply(x,y) return x * y;functionv1().functionv2().exportv1asstreamV1, v2asv2as報(bào)export/ 報(bào)錯(cuò) varm1; export m;m1。1只是一個(gè)值,不是接口。正確的寫(xiě)法是下exportvarm=varexportvarm=varm=exportvar n = 1; exportnasm;報(bào)functionf()export正exportfunctionf()/ 正確 functionf export f;可以取到模塊 實(shí)時(shí)的值。expor
17、t var foo = bar; setTimeout()=foo=baz,500);CommonJSCommonJS態(tài)更新,詳見(jiàn)下文Module 的加載實(shí)現(xiàn)一節(jié)。最后,export命令可以出現(xiàn)在模塊的任何位置,只要處于模塊頂層就可以。如果ES6functionfoo()exportdefaultbar/importexportJS/importName,lastName,yearfromfunction/importName,lastName,yearfromfunctionsetName(element) element.textContent =Name+importprofile.js
18、文件,并從中輸入變量。import importlastNamernamefrom.jsJavaScript 引擎該模塊的位置。importmyMethodfromimportfoofromimport是靜態(tài)執(zhí)行,所以不能使用表達(dá)式和變量,這些只有在運(yùn)行時(shí)才能得報(bào)importf+oofrom報(bào)letmodule=importfoofrom報(bào)if(x=1)importfoofromelseimportfoofromimportimportimportlodash; importimportfoofrommy_module; importbarfromimportfoo,barfrommy_mod
19、ule實(shí)例。也就是說(shuō),importSingletonCommonJSimport React from React;export defaultimport命令的時(shí)候,用戶需要知道所要加載的變量default命令,為模塊指定默認(rèn)輸出。/export-exportdefaultfunction() 其他模塊加載該模塊時(shí),import命令可以為該/import-importcustomNamefrom./export-default; customName(); / fooexportdefault/export-exportdefaultfunctionfoo()或者寫(xiě)function foo() exportdefault或者寫(xiě)function foo() exportdefaultexportdefaultfunctioncrc32輸/importcrc32fromcrc32輸exportfunctioncrc32輸/importcrc32fromcrc32輸上面代碼的兩組寫(xiě)法,第一組是使用 export de
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度市政道路鋼筋施工分包合同
- 便利店?duì)I業(yè)員個(gè)人工作總結(jié)2024(9篇)
- 2025年電影產(chǎn)業(yè)收益分配策略協(xié)議
- 2025年臨時(shí)建筑項(xiàng)目施工合同樣本
- 2025年鑄幣及貴金屬制實(shí)驗(yàn)室用品項(xiàng)目申請(qǐng)報(bào)告模板
- 2025年聚苯硫醚(PPS)及合金項(xiàng)目規(guī)劃申請(qǐng)報(bào)告
- 2025年升級(jí)版?zhèn)€人代表授權(quán)合同
- 2025年小區(qū)護(hù)衛(wèi)服務(wù)合同范本
- 2025年醫(yī)療機(jī)構(gòu)衛(wèi)生用品清潔服務(wù)協(xié)議
- 2025年公民投票統(tǒng)一授權(quán)協(xié)議
- 學(xué)校食堂餐廳管理者食堂安全考試題附答案
- 同等學(xué)力英語(yǔ)申碩考試詞匯(第六版大綱)電子版
- 中日合同范本
- T-CARM 002-2023 康復(fù)醫(yī)院建設(shè)標(biāo)準(zhǔn)
- 第八版神經(jīng)病學(xué)配套課件-12-中樞神經(jīng)系統(tǒng)感染性疾病
- 污水管網(wǎng)計(jì)算說(shuō)明書(shū)
- 15MW風(fēng)力發(fā)電機(jī)
- 正面管教 讀書(shū)分享(課堂PPT)
- 肌肉注射流程
- 互聯(lián)網(wǎng)銷(xiāo)售卷煙(煙草)案件的分析
- 公務(wù)員考察政審表樣本
評(píng)論
0/150
提交評(píng)論