Click or drag to resize

HostFunctionsnewObjT(Object) Method

Creates a host object of the specified type. This version is invoked if the specified type can be used as a type argument.

Namespace: Microsoft.ClearScript
Assembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.4.5
Syntax
public T newObj<T>(
	params Object[] args
)

Parameters

args  Object
Optional constructor arguments.

Type Parameters

T
The type of object to create.

Return Value

T
A new host object of the specified type.
Remarks

This function is provided for script languages that do not support external instantiation. It is overloaded with newObj(Object, Object) and selected at runtime if T can be used as a type argument.

For information about the mapping between host members and script-callable properties and methods, see AddHostObject.

Example
The following code imports the Random class, creates an instance using the Random(Int32) constructor, and calls the NextDouble method. It assumes that an instance of ExtendedHostFunctions is exposed under the name "host" (see AddHostObject).
JavaScript
var RandomT = host.type("System.Random");
var random = host.newObj(RandomT, 100);
var value = random.NextDouble();
See Also