JsExtensions Class

This is not a class, but contains some methods that will be added to the standard Javascript objects.

Item Index

Methods
Array.prototype.clone () Array

Makes a shallow copy of the array.

Returns:

Array:
A shallow copy of the array

Array.prototype.contains ( element ) Boolean

Checks whether the array contains a given element.

Parameters:

  • element Any

    The element to search for

Returns:

Boolean:
True if the array contains a given element

Array.prototype.equals ( array ) Boolean

Checks whether the two arrays are same.

Parameters:

  • array Any

    The array to compare to

Returns:

Boolean:
True if the two arrays are same

Math.randomInt ( max ) Number [static]

Generates a random integer in the range (0, max-1).

Parameters:

  • max Number

    The upper boundary (excluded)

Returns:

Number:
A random integer

Number.prototype.clamp ( min , max ) Number

Returns a number whose value is limited to the given range.

Parameters:

  • min Number

    The lower boundary

  • max Number

    The upper boundary

Returns:

Number:
A number in the range (min, max)

Number.prototype.mod ( n ) Number

Returns a modulo value which is always positive.

Parameters:

  • n Number

    The divisor

Returns:

Number:
A modulo value

Number.prototype.padZero ( length ) String

Makes a number string with leading zeros.

Parameters:

  • length Number

    The length of the output string

Returns:

String:
A string with leading zeros

String.prototype.contains ( string ) Boolean

Checks whether the string contains a given string.

Parameters:

  • string String

    The string to search for

Returns:

Boolean:
True if the string contains a given string

String.prototype.format ( ...args ) String

Replaces %1, %2 and so on in the string to the arguments.

Parameters:

  • ...args Any

    The objects to format

Returns:

String:
A formatted string

String.prototype.padZero ( length ) String

Makes a number string with leading zeros.

Parameters:

  • length Number

    The length of the output string

Returns:

String:
A string with leading zeros