ES6 Arrow Function & this bug

ES6 Arrow Function & this bug

ES6 Arrow Function & this bug_第1张图片


    let accHeadings = document.querySelectorAll(`.accordionItemHeading`); // NodeList(3)
    // let accHeadings = [...document.querySelectorAll(`.accordionItemHeading`)];

    for (let i = 0; i < accHeadings.length; i++) {
        accHeadings[i].addEventListener("click", function(e) {
            console.log(`this`, this);
            console.log(`e.target`, e.target);
        });
    }
    for (let i = 0; i < accHeadings.length; i++) {
        // ES6 Arrow Function & this bug
        accHeadings[i].addEventListener("click", () => {
            console.log(`this`, this);
        }, false);
    }

ES6 Arrow Function & this bug_第2张图片






    
    
    
    
    
    ES6 Arrow Function & this bug



    

ES6 Arrow Function & this bug

About accordions

Accordion items

How to use a JavaScript accordion

转载于:https://www.cnblogs.com/xgqfrms/p/9203187.html

你可能感兴趣的:(ES6 Arrow Function & this bug)