Skip to content

Instantly share code, notes, and snippets.

@kbshl
Forked from FokkeZB/app.js
Last active October 30, 2017 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/9c2b52d148b90878c73e to your computer and use it in GitHub Desktop.
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
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