Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created September 17, 2010 20:01
Show Gist options
  • Save rafaelrinaldi/584840 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/584840 to your computer and use it in GitHub Desktop.
Useful method to fire a function without be careful about null pointer exception.
package rinaldi.util
{
/**
*
* Useful method to fire a function without be careful about null pointer exception.
*
* @param p_function Function to be fired.
* @param args A list of parameters.
*
* @example
* <pre>
* import rinaldi.util.fire;
*
* const nullMethod : Function;
*
* // Fire the method "sum();" passing 5 and 5 as arguments
* fire(sum, 5, 5);
*
* function sum( p_a : Number, p_b : Number ) : void {
* trace(p_a + p_b);
* }
*
* // Nothing will be fired
* fire(nullMethod);
* </pre>
*
* @see rinaldi.util
*
* @date 23/08/2010
* @author Rafael Rinaldi (rafaelrinaldi.com)
*
*/
public function fire( p_function : Function, ...args ) : void
{
if(p_function != null) p_function.apply(this, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment