Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Excerpt

A quick way to check if an object is a function...

 

Syntax

The .isFunction property is added to all objects, but only returns true on functions.

Code Block
themeRDark
languagejavascript
linenumberstrue
var returnValue = obj.isFunction;

Return value

ValueTypeNotesAPI Version
trueBooleanThe object is a function1.0
falseBooleanThe object is not a function1.0

Examples

Pre-check that a value is not null before using .isFunction...

Code Block
themeRDark
languagejavascript
linenumberstrue
var val = null;
 
if (val.isFunction) { // Reference Error (null.isFunction not defined)
}
 
if (val && val.isFunction) { // false
	// val is a function
}
 
// alternate approach using typeOf()
if (typeOf(val) == "function") { // false
	// val is a function
}
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Type Checking

Topics:

Child pages (Children Display)
alltrue
depthall
pageType Checking
excerpttrue