Created
October 23, 2012 13:53
-
-
Save iskugor/3938865 to your computer and use it in GitHub Desktop.
Titanium "once" 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
function once(component, eventName, callback) { | |
if(component && component.addEventListener && eventName && callback) { | |
var wrappedCallback = function(e) { | |
component.removeEventListener(eventName, wrappedCallback); | |
callback.call(component, e); | |
}; | |
component.addEventListener(eventName, wrappedCallback); | |
} else { | |
Ti.API.error('"once" function illegal parameter'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment