Obsolete since JSAPI 26
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Determine whether the currently executing JSNative was called as a constructor.

JS_IsConstructing has been removed in bug 918462. Use CallArgs::isConstructing or CallReceiver::isConstructing instead.

Syntax

JSBool
JS_IsConstructing(JSContext *cx, jsval *vp);
Name Type Description
cx JSContext * The cx parameter passed to the JSNative.
vp jsval * The vp parameter passed to the JSNative.

Description

JS_IsConstructing must be called only from a JSNative called from the engine. cx and vp must be the arguments that the engine passed to that JSNative.

JS_IsConstructing returns JS_TRUE if the native was defined with JSFUN_CONSTRUCTOR (JS_InitClass automatically sets that flag when defining a constructor) and it was called as a constructor, either from JavaScript, using the new keyword, or from C/C++ using a JSAPI function such as JS_ConstructObject. Otherwise it returns JS_FALSE.

Ordinary non-constructor JSNatives have no need to call this; it always returns JS_FALSE for such functions.

Many constructors do not need to call it either. In the common case where a constructor should have the same behavior (creating a new object) whether it is called with the new keyword or not, it does not need to call JS_IsConstructing.