How do I check if the return variable is a function?
var testController = function() {
alert('123');
}
$(function() {
$('[mfour]').each(function(e, t) {
var a = $(t).attr('mfour');
console.log($.isFunction(testController));
console.log($.isFunction(a));
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div mfour="testController">asd</div>
Notice that on first console.log
returns TRUE when the function name is hard-coded while on the second console.log
if the variable is being evaluated returns FALSE.
It is kind of weird because var a
returns testController
.
Here's the jsFiddle.
My goal here is to run certain functions base on the mfour attribute. So in the example above, testController will run testController function.