Wamkelekile iJavaScript 2.0

IJavaScript ilawula iwebhu kunye ne-ECMAScript, isiseko solwimi siyakhula. Inkqubo entsha (i-ES6 okanye iJS2), elindelwe embindini walo nyaka, izisa izinto ezintsha ezinokulingwa namhlanje. IFirefox okwangoku ineyona nkxaso ilungileyo , kodwa i-polyfill ngokusebenzisa izinto ezibizwa ngokuba ngabadlulisi ezifana neGoogle Traceur nazo zinokwenzeka. Oku kulandelayo kukujonga ngokufutshane kwezinto ezintsha ze-ES6.


Igama elitsha elingundoqo let let do many things better than var : Scoping ngoku iziphatha ngokuchanekileyo njengakwezinye iilwimi (C / C ++, Java), yiyo loo nto ukuba iibhloko ngoku zinendawo yazo. Ukuphakamisa, okt ukuzisa ngaphambili izibhengezo eziguqukayo (hayi ii-asayinimenti zexabiso) ngaphakathi komgangatho wazo, kuyalungiswa:

console.log(x);
var x = 'foo'; 
// undefined

console.log(y);
let y = 'bar';
// not initialized

Inani lezinye izinto ezintsha lide: ii-constants (const), amaxabiso asisiseko emisebenzi (function pow (a, b = 2) {Return Math.pow (a, b);}), notation entsha yemisebenzi (let pow = (a, b = 2) => Math.pow (a, b);), uninzi lwemisebenzi emitsha (repeat (), contains,), startsWith (), find (), findIndex ()), ulwakhiwo olutsha lweluphu ye ... ye.

Iindidi zedatha entsha esetiweyo, imephu, ummeleli kunye nesimboli, ukungeniswa kwe (iinxalenye zezinye iifayile zeJavaScript ngokungenisa kunye nes syntax entsha enomdla yeeklasi kunye nelifa kufuneka zikhankanywe. Kodwa rhoqo kukho izinto ezincinci kodwa ezilindelwe ixesha elide ezinje ngokuqhekeka komgca kuluhlu lwamagama (qaphela amanqaku akhethekileyo ocaphulo):

`foo

bar`

IJavaScript kudala ingaphezulu kwesixhobo seqhinga elincinci lewebhusayithi- idala usetyenziso olunamandla, olusebenzayo oluphezulu lwewebhu olungaphantsi kunabo be desktop. Ngenani elikhulu lezinto ezintsha eziluncedo kunye nenkxaso esele ifumaneka kwi-ES6, inkqubo iphinda-phinda kamnandi.

Ngubani ongasoloko efuna ukukhangela ukulingana kwamanani amabini ngoncedo lweNombolo entsha yePSPSON , ixabiso lalo ngumahluko phakathi kwe-1 kunye nexabiso elilandelayo lokudada?

let cmp = (a,b) => Math.abs(a-b) 
Emva