This AI is still in early stages of development.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

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.

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...

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
}
Availability STABLE

Requires:

Contents

Jump to:

Type Checking

Topics:

  • classOf()Returns the name of the class (constructor) used to create an object...
  • object.isFunctionA quick way to check if an object is a function...
  • typeOf()Returns a more accurate object type name than Javascript's native "typeof https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/typeof" operator...
  • object.isArrayA quick way to check if an object is an array...

 

  • No labels