Skip to content

Instantly share code, notes, and snippets.

@kjantzer
Created December 19, 2015 00:17
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 kjantzer/6d394ca7cb43cb8df2fd to your computer and use it in GitHub Desktop.
Save kjantzer/6d394ca7cb43cb8df2fd to your computer and use it in GitHub Desktop.
determineFn = function(fn, ctx){
// look for function name on the context
if( _.isString(fn) ){
if( !ctx ){
console.error('Could not bind onClick “'+fn+'”; please provide a context')
fn = null;
}else if( ctx[fn] && _.isFunction(ctx[fn]) ){
fn = ctx[fn].bind(ctx);
}else{
console.error('Method “'+fn+'” does not exist on context:', ctx)
fn = null;
}
}else if( fn && _.isFunction(fn) ){
fn = fn.bind(ctx)
}else{
fn = null;
}
return fn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment