if call function once this
var button = document.queryselector('button'); button.addeventlistener('click', once); function once() { console.log('one'); button.removeeventlistener('click', once); } it's calling once.
but if called once()
var button = document.queryselector('button'); button.addeventlistener('click', once()); function once() { console.log('one'); button.removeeventlistener('click', once()); } exception throws
exception: internalerror: recursion
could please explain why happening.
() after function name invoke's function. button.addeventlistener('click', once()); bind return value of once() method undefined.
and since once() called recursively without break statement, getting internalerror: recursion.
you should pass function reference.
button.addeventlistener('click', once); for additional info:
Comments
Post a Comment