Function.validateParameters Function

Validates the parameters to a method are as expected.

var a = objVar.validateParameters(parameters,expectedParameters,validateParameterCount);

parameters

Array of parameter values passed to the method.

expectedParameters

Array of JSON objects describing the expected parameters.

validateParameterCount

true if extra parameters are prohibited, false if they should be ignored. The default is true.

True if the parameters are validated, otherwise null.

The following example shows how to use the validateParameters function.

Array.insert = function Array$insert(array, index, item) {
    var e = Function. validateParameters(arguments, [
        {name: "array", type: Array, elementMayBeNull: true},
        {name: "index", mayBeNull: true},
        {name: "item", mayBeNull: true}
    ]);
    if (e) throw e;
    ...
}
Show: