JavaScript
This document describes extensions to the standard JavaScript language.
These are defined in the common library, but grouped together
here for convenience. There is no need to import this file.
Create a JavaScript Array object from any "array-like" object,
including a Java array. An array-like object a includes a length property
and a sequence of zero or more sequential properties a[0],
a[1], a[2], ... a[ a.length-1 ].
returns an Array containing a copy of the elements of arrayLikeObject
Makes objects created with the calling constructor a "subclass" of
the superConstructor by chaining
constructor.prototype to superConstructor.prototype.
Example:
function Super() {
this.x = "super";
}
Super.prototype.getX = function getX() {
return this.x;
}
function Sub() {
Super.call( this );
this.x = "sub";
}
Sub.subclass( Super );
var subobj = new Sub();
println( subobj.getX() );
constructor | the name of the subclass constructor function |
superConstructor | the name of the superclass constructor function |
When called, prints a standard warning message if script warnings are enabled.
This function is not meant to be called directly. Rather, this function is
assigned to a property in an object's prototype to make that function
abstract. When a subclassing object fails to override the abstract method,
calls to the abstract method will thus display a warning message for the
developer.
Converts this number to a Java Integer object.
Any fractional part is discarded. If the number lies outside the
range of possible Integer values, an exception is thrown.
returns this number as a java.lang.Integer
Converts this number to a Java Long object.
Any fractional part is discarded. If the number lies outside the
range of possible Long values, an exception is thrown.
returns this number as a java.lang.Long
Converts this number to a Java Float object.
If the number lies outside the range of possible Float values,
an exception is thrown.
returns this number as a java.lang.Float
Removes leading and trailing whitespace from this string.
returns this string with whitespace removed from both ends
Removes leading whitespace from this string.
returns this string with whitespace removed from the start
Removes trailing whitespace from this string.
returns this string with whitespace removed from the end
Replaces every occurrence of pattern with replacement,
where both values are plain strings rather than regular expressions.
The replacements are made as if by processing the string from left
to right and replacing each time a match is possible. For example,
the following code results in bb rather than bbb:
println( "aaaa".replaceAll( "aa", "b" ) );
pattern | the substring to replace all occurrences of |
replacement | the substring to replace each occurrence with |
returns the replaced string
Returns true if pattern is a prefix of this string.
"meta".startsWith( "me" );
"Random".startsWith( "and" );
pattern | the string to match against the start of this string |
returns true if and only if this string starts with pattern
Returns true if pattern is a suffix of this string.
"bartend".endsWith( "tend" );
"moose".endsWith( "oos" );
pattern | the string to match against the end of this string |
returns true if and only if this string ends with pattern
Prevents the named methods from being enumerated. This is most useful when
extending Object's prototype with new functions, as it maintains
the ability to use plain objects as a map.
var obj = {};
Object.prototype.blight = function blight() {};
println( "Before:" );
for( let i in obj ) println(i);
Object.prototype.dontEnum( "blight" );
println( "After:" );
for( let i in obj ) println(i);
Escapes the characters in a string that have special meaning in a regular
expression. If a regular expression is created from the string, it will
match string literally. For example, * would be replaced
with \\* because * has special meaning in a regular
expression.
string | the string to escape |
returns a string that encodes string as regular expression
Escapes the characters in a string that have special meaning when used as
a replacement for a regular expression.
string | the string to escape |
returns a string that encodes string as regular expression replacement
Contents