⊗jsPmCxAFS 438 of 504 menu

Context with arrow function in JavaScript

The third solution to the problem is to use arrow functions, which appeared in JavaScript not so long ago. Such functions, among other things, do not have their own context, but retain the context of the parent. Let's fix our problem with an arrow function:

let elem = document.querySelector('#elem'); elem.addEventListener('blur', parent); function parent() { console.log(this.value); // shows 'text' let child = () => { console.log(this.value); // shows 'text' } child(); }

Take the code from the previous task and fix the code problem using the third method you learned.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline