addEventListener calls the function without me even asking it to

前端 未结 4 556
故里飘歌
故里飘歌 2020-11-22 02:37

So we have a page:


    First Link
    Second Link&         


        
4条回答
  •  梦毁少年i
    2020-11-22 03:07

    or you can use .bind

    function message_me(m_text){
        alert(m_text);
    }
    
    second.addEventListener('click', message_me.bind(this, 'shazam'));
    

    check MDN Documentation about 'closures'

提交回复
热议问题