ClearScript Library
ClearScript Library
ClearScript Library Reference
Microsoft.ClearScript
HostFunctions Class
HostFunctions Methods
newObj Method
newObj Method
newObj<T>(Object[]) Method
newObj(IDynamicMetaObjectProvider, Object[]) Method
newObj(Object, Object[]) Method

# HostFunctionsnewObj T(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.5.0
Syntax
C#
VB
C++
F#
Copy

    public T newObj<T>(
    	params Object[] args
    )

    Public Function newObj(Of T) (
    	ParamArray args As Object()
    ) As T

    public:
    generic<typename T>
    T newObj(
    	... array<Object^>^ args
    )

    member newObj :
            args : Object[] -> 'T

#### 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
Copy

    var RandomT = host.type("System.Random");
    var random = host.newObj(RandomT, 100);
    var value = random.NextDouble();

See Also

#### Reference

HostFunctions Class
newObj Overload
Microsoft.ClearScript Namespace
type(String, Object)

Copyright © Microsoft Corporation. All rights reserved.

Send comments on this topic to Microsoft