Created
December 19, 2015 00:17
-
-
Save kjantzer/6d394ca7cb43cb8df2fd to your computer and use it in GitHub Desktop.
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
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