Uyemukelwa iJavaScript 2.0

IJavaScript ibusa iwebhu naku-ECMAScript, umnyombo wolimi uyakhula. Ukucaciswa okusha (i-ES6 noma i-JS2), okulindelwe maphakathi nonyaka, kuletha nezinto ezintsha ezingasazanywa namuhla. IFirefox okwamanje inokusekelwa okuhle kakhulu , kepha ama-polyfill ngokusebenzisa okuthiwa abathuthi abanjengoGoogle Traceur nawo ayenzeka. Okulandelayo ukubuka konke okufushane kwezici ezintsha ze-ES6.


Igama elingukhiye elisha let lenza kangcono kakhulu kune- var : I-Scoping manje iziphatha ngokufana nezinye izilimi (C / C ++, Java), yingakho uma-block manje nawo enesilinganiso sawo. Ukuphakama, isb.ukuletha phambili izimemezelo eziguqukayo (hhayi izabelo zamanani) ngaphakathi kwesilinganiso esifanele nakho kuyalungiswa:

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

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

Inani lezinye izinto ezintsha lide: ama-constants (const), amanani azenzakalelayo emisebenzi (function pow (a, b = 2) {return Math.pow (a, b);}), i-notation entsha yemisebenzi (let pow = (a, b = 2) => Math.pow (a, b);), inqwaba yemisebenzi emisha (repeat (), contains (), startsWith (), find (), findIndex ()), ukwakhiwa okusha kwe-loop ye ... ka.

Izinhlobo ezintsha zedatha ezisethiwe, imephu, ummeleli nophawu, ukungeniswa (kwezingxenye zamanye amafayela) weJavaScript ngokungenisa kanye ne-syntax entsha enembile yamakilasi nefa nakho kufanele kushiwo. Imvamisa kukhona nezinto ezincane kepha ezikade zilindelwe njengokuthi kungenzeka ukuthi kunqamuke ulayini ezincwadini zezintambo (qaphela amamaki wokucaphuna akhethekile):

`foo

bar`

Sekuyisikhathi eside iJavaScript ingaphezu kwethuluzi lamasu amawebhusayithi amancane - idala izinhlelo zokusebenza zewebhu ezinamandla, ezisebenza kakhulu ezingaphansi neze kozakwabo bedeskithophu. Ngenani elikhulu lezinto ezintsha eziwusizo nosekelo olutholakale ku-ES6, ukwenza izinhlelo kumnandi kabili.

Ngubani ongafuni njalo ukuhlola ukulingana kwezinombolo ezimbili ngosizo lweNombolo entsha engapheli.EPSILON, inani lalo eliveza umehluko phakathi kuka-1 nenani lephuzu lokuntanta eliphakeme elilandelayo elilandelayo?

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