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.