Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught RangeError: Maximum call stack size exceeded, JavaScript

I have a problem

    open: function($type) {
          //Some code
          document.getElementById($type).addEventListener("click", l.close($type), false);
    },
    close: function($type) {
           //There is some code too
           document.getElementById($type).removeEventListener("click", l.close($type), false);
           //^ Recursion & Uncaught RangeError: Maximum call stack size exceeded
    }

What I'm doing wrong? Without this click event listener everything is working well. And what is the third parameter doing (true|false)? Thank you.

like image 830
anony_root Avatar asked Feb 29 '12 10:02

anony_root


1 Answers

You are calling the close function in the addEventListener and removeEventListener when you are trying to pass is as an argument (causing an infinite loop). Instead you should simply pass the reference to the function as follows:

document.getElementById($type).addEventListener("click", l.close, false);

And:

document.getElementById($type).removeEventListener("click", l.close, false);
like image 156
Lycha Avatar answered Oct 19 '22 21:10

Lycha