Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell if a Javascript function is defined by looking at self[name] - is this a good way?

Tags:

javascript

This is a follow up question to This Question.

I like (and understand) the solution there. However, in the code I am working in, another way to solve the same problem is used:

function exist(sFN) {
    if(self[sFN]) return true;
    return false;
}

It seems to work fine, although I don't understand how. Does it work? How? What are minuses of this approach? Should I switch to solution from the other question?

like image 504
buti-oxa Avatar asked Dec 06 '22 07:12

buti-oxa


1 Answers

Try this:

function exist(sFN) {
 return (typeof sFN == 'function');
}
like image 108
Nick Craver Avatar answered Dec 24 '22 14:12

Nick Craver