-
-
Save kbshl/9c2b52d148b90878c73e to your computer and use it in GitHub Desktop.
Titanium Mobile: Add event listener once respectively remove event listener for anonymous callback function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({ | |
backgroundColor: 'white' | |
}); | |
win.addEventListener('click', function foo(e) { // note the named function expression needed for the second way | |
// oringal idea by @fukhaos | |
// http://www.tidev.io/2014/09/10/the-case-against-ti-app-fireevent-2/#comment-13013 | |
e.source.removeEventListener(e.type, arguments.callee); | |
// better - strict - one by @tonylukasavage | |
// https://twitter.com/tonylukasavage/status/511887565100949505 | |
e.source.removeEventListener(e.type, foo); | |
alert('I will only fire once!'); | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment