473,378 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

"how to test for functions" should be in the FAQ, yes?

<FAQENTRY>

Weird. I go to Google and search for "javascript faq". These are the
top results:

http://www.javascripter.net/faq/index.htm
http://www.irt.org/script/script.htm
http://www.jibbering.com/faq/

I've got what I assume is an FAQ question:

"How can I check to see if a function has been defined?"
I searched on those pages for stuff like "define" and "function" and
"test" and didn't find my question.

Sep 21 '07 #1
4 1344
On Sep 21, 4:20 pm, Jake Barnes <lkrub...@geocities.comwrote:
<FAQENTRY>

Weird. I go to Google and search for "javascript faq". These are the
top results:

http://www.javascripter.net/faq/inde...ering.com/faq/

I've got what I assume is an FAQ question:

"How can I check to see if a function has been defined?"

I searched on those pages for stuff like "define" and "function" and
"test" and didn't find my question.
To answer your question, "functions" aren't special in this case - you
need a general ability to test if an identifier is defined:

if (typeof possibleFn == 'function') {
// do stuff
}

gives you what you want; in general you can use

if (typeof possibleFn != 'undefined') {
// do stuff
}

for all your needs, unless you suspect possibleFn may be assigned a
non-function value somewhere, in which case the former (typeof
(possibleFn) == 'function') is what you want.

I don't know why the comp.lang.javascript FAQ is ranked 3rd in the
Google results. It's probably a matter of those other sites putting
greater importance on SEO.

Also, I doubt that this specific question will find its way into the
FAQ, unless under the guise of the general case (checking any
identifier's status); there are infinite questions that beginners ask,
and once they've read the FAQ, it's reasonable to come here to find
answers to stuff that's not there.

-David

Sep 22 '07 #2
David Golightly wrote:
On Sep 21, 4:20 pm, Jake Barnes wrote:
<snip>
>I've got what I assume is an FAQ question:

"How can I check to see if a function has been defined?"
<snip>
To answer your question, "functions" aren't special in
this case - you need a general ability to test if an
identifier is defined:

if (typeof possibleFn == 'function') {
// do stuff
}

gives you what you want; in general you can use

if (typeof possibleFn != 'undefined') {
// do stuff
}
<snip>
Also, I doubt that this specific question will find its way
into the FAQ, unless under the guise of the general case
(checking any identifier's status);
<snip>

And the general answer is already in the FAQ, in the resources linked to
from 4.26.

Richard.

Sep 22 '07 #3
On Sep 21, 9:15 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
David Golightly wrote:
On Sep 21, 4:20 pm, Jake Barnes wrote:
<snip>
I've got what I assume is an FAQ question:
"How can I check to see if a function has been defined?"
<snip>
To answer your question, "functions" aren't special in
this case - you need a general ability to test if an
identifier is defined:
if (typeof possibleFn == 'function') {
// do stuff
}
gives you what you want; in general you can use
if (typeof possibleFn != 'undefined') {
// do stuff
}
<snip>
Also, I doubt that this specific question will find its way
into the FAQ, unless under the guise of the general case
(checking any identifier's status);

<snip>

And the general answer is already in the FAQ, in the resources linked to
from 4.26.

Hmm, at jibbering, 4.26 is this:

4.26 How do I detect Opera/Netscape/IE?

http://www.jibbering.com/faq/#FAQ4_26
I don't see numbers for http://www.javascripter.net/faq/index.htm

At irt.org, 426 points at this:

http://www.irt.org/script/426.htm

Q426 How can I change the mouse pointer to an hourGlass prior to long
running scripts, then reset after the script complete?

So I don't see what you're suggesting. None of these 3 FAQs answer my
question, but I think my question, and the answer, should be in an
FAQ.

Sep 23 '07 #4
On Sep 21, 8:11 pm, David Golightly <davig...@gmail.comwrote:
On Sep 21, 4:20 pm, Jake Barnes <lkrub...@geocities.comwrote:

To answer your question, "functions" aren't special in this case - you
need a general ability to test if an identifier is defined:

if (typeof possibleFn == 'function') {
// do stuff

}

gives you what you want; in general you can use

if (typeof possibleFn != 'undefined') {
// do stuff

}

for all your needs, unless you suspect possibleFn may be assigned a
non-function value somewhere, in which case the former (typeof
(possibleFn) == 'function') is what you want.

I don't know why the comp.lang.javascript FAQ is ranked 3rd in the
Google results. It's probably a matter of those other sites putting
greater importance on SEO.

Also, I doubt that this specific question will find its way into the
FAQ, unless under the guise of the general case (checking any
identifier's status); there are infinite questions that beginners ask,
and once they've read the FAQ, it's reasonable to come here to find
answers to stuff that's not there.
You don't feel this question is asked frequently? I had the
impression it was in the category of "common".

Sep 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: elektrophyte | last post by:
I was looking at the PHP function "call_user_func()" (http://us3.php.net/call_user_func). It appears that this will solve a design problem in the app I'm working on. (I'm writing a class that will...
1
by: Pete Mahoney | last post by:
Ok I use a textarea to store data input by the user, and then upon them clicking the submit button I store this data to a database. The problem is once the user inputs too much data (about 3...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
6
by: chris yoker via DotNetMonster.com | last post by:
hiya, i have an xml doc, and I'd like to assign lookup values. Eg, if the "PRODUCT-TYPE" is 6, then I insert "bike" into the innerText. <code> <rows> <row> <PRODUCT-TYPE>6</PRODUCT-TYPE>...
9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
0
by: Kevin Bracey | last post by:
I've been implemening Annex F in my compiler, and one issue to do with "pure" functions has come to my attention. The compiler has for a long time had a __pure keyword (and a related pragma...
12
by: bokiteam | last post by:
Hi All, I dont' know why I can not pop up a message box. MsgBox("test") it is ok in vb6... Best regards, Boki.
1
by: Mikewill | last post by:
I need to fix my Moodle database and someone has told me that they "used their server's CPanel and the mySQL feature to "check" then "fix" his moodle database". I dont have a cpanel and was hoping...
3
by: Zerozone | last post by:
I mean : How can C write these functions... I would like to know it, so you can show me where can I find about this infomation ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.