The built-in ECMAScript Objects [ECMA11a(p.S15, p.p.102)] are supported and their properties are annotated with types as described in this chapter. The semantics of these properties do not change. The short description is copied from [ECMA11a] repeated here for convenience.
Object is the super type of all declared types and N4Object. It is almost similar to the JavaScript type Object except that no properties may be dynamically added to it. In order to declare a variable to which properties can be dynamically added, the Object+ type has to be declared (cf.
[_dynamic]).
constructor:ObjectReturns a reference to the Object function that created the instance’s prototype.
toString():ObjectReturns a string representing the specified object.
toLocaleString():ObjectReturns a string representing the object. This method is meant to be overridden by derived objects for locale-specific purposes.
valueOf():ObjectReturns the primitive value of the specified object.
hasOwnProperty(prop:String):BooleanReturns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
isPrototypeOf(object:Object):BooleanReturns a boolean indication whether the specified object is in the prototype chain of the object this method is called upon.
propertyIsEnumerable(prop:String):BooleanReturns a boolean indicating if the internal ECMAScript DontEnum attribute is set.
getPrototypeOf(object:Object):ObjectReturns the prototype of the specified object.
create(object:Object,properties:Object=):ObjectCreates a new object with the specified prototype object and properties.
defineProperty(object:Object,prop:Object,descriptor:Object):ObjectDefines a new property directly on an object or modifies an existing property on an object and returns the object.
defineProperties(object:Object,properties:Object):ObjectDefines new or modifies existing properties directly on an object, returning the object.
seal(object:Object,properties:Object)Seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.
freeze(object:Object):ObjectFreezes an object: that is, prevents new properties from being added to it, prevents existing properties from being removed, prevents existing properties or their enumerability, configurability, or writability from being changed. In essence, the object is made effectively immutable. The method returns the object being frozen.
preventExtensions(object:Object):ObjectPrevents new properties from ever being added to an object (i.e. prevents future extensions to the object).
isSealed(object:Object):Boolean staticDetermine if an object is sealed.
isFrozen(object:Object):BooleanDetermine if an object is frozen.
isExtensible(object:Object):BooleanDetermines if an object is extensible (whether it can have new properties added to it).
keys(object:Object):Array<String>Returns an array of all own enumerable properties found upon a given object in the same order as that provided by a for-in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
String is a global object that may be used to construct String instances and is a sub class of Object.
number: length The length of a string.
String(thing:Object=)-
anchor(anchorname:String):StringCreates an HTML anchor.
big():StringReturns a string in a big font.
blink():StringReturns a string in a blinking string.
bold():StringReturns a string in a bold font.
charAt(index:Number):StringReturns the character at a specified position.
charCodeAt(index:Number):NumberReturns the Unicode of the character at a specified position.
concat(strings:String…):StringJoins two or more strings.
equals(object:Object):Boolean -
equalsIgnoreCase(object:Object):Boolean -
fromCharCode(num:Any…):StringReturns a string created by using the specified sequence of Unicode values.
fixed():StringReturns a string as teletype text.
fontcolor(color):StringReturns a string in a specified color.
fontsize(size):StringReturns a string in a specified size.
indexOf(searchValue, fromIndex:Number=):NumberReturns the position of the first occurrence of a specified string value in a string.
italics():StringReturns a string in italic.
lastIndexOf(searchValue, fromIndex:Number=):NumberReturns the position of the last occurrence of a specified string value, searching backwards from the specified position in a string.
link(url):StringReturns a string as a hyperlink.
localeCompare(otherString):NumberThis method returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
match(search value):StringSearches for a specified value in a string.
replace(findString,newString):StringReplaces some characters with some other characters in a string.
search(search string):NumberSearches a string for a specified value.
slice(beginSlice:Number, endSclice:Number=):StringExtracts a part of a string and returns the extracted part in a new string.
small():StringReturns a string in a small font.
split(separator, howmany:Number=):Array<String>Splits a string into an array of strings.
strike():StringReturns a string with a strikethrough.
sub():StringReturns a string as subscript.
substr(start:Number,length:Number=):StringExtracts a specified number of characters in a string, from a start index.
substring(beginIndex:number,endIndex:Number=):StringExtracts the characters in a string between two specified indices.
sup():StringReturns a string as superscript.
toLocaleUpperCase():StringReturns a string in lowercase letters.
toString():StringReturns a String value for this object.
toUpperCase():StringReturns a string in uppercase letters.
valueOf():StringReturns the primitive value of a String object.
String(value:Object=)Static constructor.
Number does not have a super class.
MAX_VALUE:NumberThe largest representable number.
MIN_VALUE:NumberThe smallest representable number.
NaN:NumberSpecial 'not a number' value.
NEGATIVE_INFINITY:NumberSpecial value representing negative infinity, returned on overflow.
POSITIVE_INFINITY:NumberSpecial value representing infinity, returned on overflow.
toExponential(numberOfDecimals:Number=):StringConverts the value of the object into an exponential notation.
toFixed(numberOfDecimals:Number=):StringFormats a number to the specified number of decimals.
toPrecision(numberOfDecimals:Number=):StringConverts a number into an exponential notation if it has more digits than specified.
valueOf():NumberReturns the primitive value of a Number object.
toString(radix:Number=):StringReturns a String value for this object. The toString method parses its first argument and attempts to return a string representation in the specified radix (base).
toLocaleString(locales: String|[String]=undefined, options: rNumberFormatOptions=undefined): StringReturns a locale-specific String value for this object. The toLocalString accepts two optional arguments. The semantics of these arguments
is defined in ECMA-402 (Internationalization API Specification).
In N4JS, the base definition does not define that method, instead Number inherits toLocaleString from Object. The specialized
definition is found in the runtime library n4js-runtime-ecma402.
Number(value:Object=):NumberStatic constructor.
Function does not have a super class.
prototype:ObjectAllows the addition of properties to the instance of the object created by the constructor function.
length:NumberSpecifies the number of arguments expected by the functio
apply(thisArg,argsArray:Array=):ObjectApplies the method of another object in the context of a different object (the calling object); arguments can be passed as an Array object.
call(thisArg,arg…):ObjectCalls (executes) a method of another object in the context of a different object (the calling object); arguments can be passed as they are.
bind(thisArg:Object,arg…):FunctionCreates a new function that, when called, itself calls this function in the context of the provided this value with a given sequence of arguments preceding any provided when the new function was called.
Error does not have a super class.
name:StringError name.
message:StringError message.
Error(message:Object=):ErrorStatic Constructor.
Array is a generic type with the type parameter E and does not have a super class.
concat(array…):Array<E>)Joins two or more arrays and returns the result.
every(callback:Function):BooleanTests whether all elements in the array pass the test implemented by the provided function. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray).
filter(callback:Function):Array<E>Creates a new array with all elements that pass the test implemented by the provided function. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray).
forEach(callback:Function,thisArg=)Calls a function for each element in the array. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray). Optionally with a thisObject argument to use as this when executing callback.
indexOf(searchElement,fromIndex=):NumberReturns the first index at which a given element can be found in the array, or -1 if it is not present.
join(separator=):StringPuts all the elements of an array into a string. The elements are separated by a specified delimiter.
lastIndexOf(searchElement,fromIndex=):NumberReturns the last (greatest) index of an element within the array equal to the specified value. Will return -1 if none are found.
length():NumberThe length returns an integer representing the length of an array.
map(callback:Function,thisArg=):ArrayCreates a new array with the results of calling a provided function on every element in this array. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray). Optionally, with a thisObject argument to use as this when executing callback.
pop():ERemoves and returns the last element of an array.
push(element…):EAdds one or more elements to the end of an array and returns the new length.
reverse():Array<E>Reverses the order of the elements in an array.
shift()Removes and returns the first element of an array.
slice(start:Number,end:Number=):Array<E>Returns selected elements from an existing array.
some(callback:Function,thisArg=):BooleanTests whether some element in the array passes the test implemented by the provided function. The callback will be called with 3 arguments (elementValue,elementIndex,traversedArray). Optionally, with a thisObject argument to use as this when executing callback.
sort(sortByFunction:Function=):Array<E>Sorts the elements of an array. The function will be called with 2 arguments (a,b).
splice(index:Number,how many:Number,element…):Array<E>Removes and adds new elements to an array. Returns the removed elements as an Array.
toLocaleString():StringtoString():StringReturns a String value for Array.
unshift(element…):EAdds one or more elements to the beginning of an array and returns the new length.
Array(item:Object…)Static constructor.
Date does not have a super class.
Date():DateStatic constructor.
Date(milliseconds:Number):DateConstructor.
Date(date:Date):DateConstructor.
Date(dateString:String):DateConstructor.
Date(year:Number,month:Number,day=Number=,hour:Number=,minute:Number=,second:Number=,millisecond:Number=):DateConstructor.
parse(dateString:String):DateParses a string representation of a date, and returns the number of milliseconds since midnight Jan 1, 1970.
now():NumberReturns the numeric value corresponding to the current time.
UTC(year:Number,month:Number,date:Number=,hrs:Number=,min:Number=,sec:Number=,ms:Number=):NumberUTC takes comma-delimited date parameters and returns the number of milliseconds between January 1, 1970, 00:00:00, Universal Time and the time you specified.
getDate():NumberReturns the day of the month from a Date object (from 1-31).
getDay():NumberReturns the day of the week from a Date object (from 0-6).
getFullYear():NumberReturns the year, as a four-digit number.
getHours():NumberReturns the hour of a day (from 0-23).
getMilliseconds():NumberReturns the milliseconds of a Date object (from 0-999).
getMinutes():NumberReturns the minutes of a date (from 0-59).
getMonth():NumberReturns the month from a date (from 0-11).
getSeconds():NumberReturns the seconds of a date (from 0-59).
getTime():NumberReturns the number of milliseconds since midnight Jan 1, 1970.
valueOf():NumberReturns the primitive value of a Date object as a number data type, the number of milliseconds since midnight 01 January, 1970 UTC. This method is functionally equivalent to the getTime method.
getTimezoneOffset():NumberReturns the difference in minutes between local time and Greenwich Mean Time (GMT).
getUTCDate():NumberReturns the day of the month from a date according to Universal Time (from 1-31).
getUTCDay():NumberReturns the day of the week from a date according to Universal Time (from 0-6).
getUTCFullYear():NumberReturns the four-digit year from a date according to Universal Time.
getUTCHours():NumberReturns the hour of a date according to Universal Time (from 0-23).
getUTCMilliseconds():NumberReturns the milliseconds of a date according to Universal Time (from 0-999).
getUTCMinutes():NumberReturns the minutes of a date according to Universal Time (from 0-59).
getUTCMonth():NumberReturns the month from a Date object according to Universal Time (from 0-11).
getUTCSeconds():NumberReturns the seconds of a date according to Universal Time (from 0-59).
getYear():Number deprecatedReturns the year as a two-digit or a three/four-digit number, depending on the browser. Use getFullYear() instead!
setDate(day):NumberSets the day of the month from a Date object (from 1-31).
setFullYear(full year, month=, day=):NumberSets the year as a four-digit number.
setHours(hours,minutes=,seconds=,milis=):NumberSets the hour of a day (from 0-23).
setMilliseconds(mills):NumberSets the milliseconds of a Date object (from 0-999).
setMinutes(minutes,=seconds,=millis):NumberSets the minutes of a date (from 0-59).
setMonth" directType="Number(month,day=):NumberSets the month from a date (from 0-11).
setSeconds(seconds,millis=):numberSets the seconds of a date (from 0-59).
setTime(mills):NumberSets the number of milliseconds since midnight Jan 1, 1970.
setUTCDate(day):NumberSets the day of the month from a date according to Universal Time (from 0-6).
setUTCFullYear(fullyear,month=,day=):NumberSets the four-digit year from a date according to Universal Time.
setUTCHours(hours,minutes=,seconds=,millis=):NumberSets the hour of a date according to Universal Time (from 0-23).
setUTCMilliseconds(mills):NumberSets the milliseconds of a date according to Universal Time (from 0-999).
setUTCMinutes(minutes,seconds=,millis=):NumberSets the minutes of a date according to Universal Time time (from 0-59).
setUTCMonth(month,day=):NumberSets the month from a Date object according to Universal Time (from 0-11).
setUTCSeconds(seconds,millis=):NumberSets the seconds of a date according to Universal Time (from 0-59).
setYear(year):Number deprecatedSets the year, as a two-digit or a three/four-digit number, depending on the browser. Use setFullYear() instead!!
toDateString():StringReturns the date portion of a Date object in readable form.
toLocaleDateString(locales: String|[String]=undefined, options: rDateTimeFormatOptions=undefined): StringConverts a Date object, using locales and options as defined in DateTimeFormat of ECMA-402 (Internationalization API), to a string and returns the date and time portion.
The toLocalString accepts two optional arguments. The semantics of these arguments is defined in
ECMA-402 (Internationalization API Specification).
The specialized definition is found in the runtime library n4js-runtime-ecma402.
toLocaleString(locales: String|[String]=undefined, options: rDateTimeFormatOptions=undefined): StringConverts a Date object, using locales and options as defined in DateTimeFormat of ECMA-402 (Internationalization API), to a string.
The toLocalString accepts two optional arguments. The semantics of these arguments is defined in
ECMA-402 (Internationalization API Specification).
In N4JS, the base definition does not define that method, instead Date inherits toLocaleString from Object. The specialized
definition is found in the runtime library n4js-runtime-ecma402.
toLocaleTimeString(locales: String|[String]=undefined, options: rDateTimeFormatOptions=undefined): StringConverts a Date object, using locales and options as defined in DateTimeFormat of ECMA-402 (Internationalization API), to a string and returns the time portion.
The semantics of these arguments is defined in
ECMA-402 (Internationalization API Specification).
The specialized definition is found in the runtime library n4js-runtime-ecma402.
toString():StringReturns a String value for this object.
toTimeString():StringReturns the time portion of a Date object in readable form.
toUTCString():StringConverts a Date object, according to Universal Time, to a string.
Math is not instantiable and only provides static properties and methods.
E:NumberEuler’s constant and the base of natural logarithms, approximately 2.718.
LN2:NumberNatural logarithm of 2, approximately 0.693.
LN10:NumberNatural logarithm of 10, approximately 2.302.
LOG2E:NumberBase 2 logarithm of E, approximately 1.442.
LOG10E:NumberBase 10 logarithm of E, approximately 0.434.
PI:NumberRatio of the circumference of a circle to its diameter, approximately 3.14159.
SQRT1_2:NumberSquare root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
SQRT2:NumberSquare root of 2, approximately 1.414.
abs(x):NumberReturns the absolute value of a number.
acos(x:Number):NumberReturns the arccosine of a number.
asinx:Number):NumberReturns the arcsine of a number.
atan(x:Number):NumberReturns the arctangent of a number.
atan2(y:Number,x:Number):NumberReturns the arctangent of the quotient of its arguments.
ceil(x):NumberReturns the smallest integer greater than or equal to a number.
cos(x):NumberReturns the arctangent of the quotient of its arguments.
exp(x):NumberReturns Enumber, where number is the argument, and E is Euler’s constant (2.718…), the base of the natural logarithm.
floor(x):NumberReturns the largest integer less than or equal to a number.
log(x):NumberReturns the natural logarithm (loge, also ln) of a number.
max(value…):NumberReturns the largest of zero or more numbers.
min(value…):NumberReturns the smallest of zero or more numbers.
pow(base:Number,exponent:Number):NumberReturns base to the exponent power, that is, baseexponent.
random():NumberReturns a pseudorandom number between 0 and 1.
round(x:Number):NumberReturns the value of a number rounded to the nearest integer.
sin(x:Number):NumberReturns the sine of a number.
sqrt(x:Number):NumberReturns the positive square root of a number.
tan(x:Number):NumberReturns the tangent of a number.
RegExp does not have a super class.
global:BooleanWhether to test the regular expression against all possible matches in a string, or only against the first.
ignoreCase:BooleanWhether to ignore case while attempting a match in a string.
lastIndex:NumberThe index at which to start the next match.
multiline:BooleanWhether or not to search in strings across multiple lines.
source:StringThe text of the pattern.
exec(str:String):ArrayExecutes a search for a match in its string parameter.
test(str:String):BooleanTests for a match in its string parameter.
JSON is a global object and a subclass of Object. Its functionality is provided by two static methods.
It is not possible to create new instances of type JSON.
The JSON object does not define own properties.
The JSON object does not define own methods.
The parse function parses a JSON text (a JSON-formatted String) and produces an ECMAScript value. The JSON format is a restricted form of ECMAScript literal. JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript arrays. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and null. For detailed information see [ECMA11a(p.S15.12.2)]
The optional reviver parameter is a function that takes two parameters (key and value). It can filter and transform the results. It is called with each of the key/value pairs produced by the parse and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns then the property is deleted from the result.
The stringify function returns a String in JSON format representing an ECMAScript value. It can take three parameters. The first parameter is required. The value parameter is an ECMAScript value which is usually an object or array, although it can also be a String, Boolean, Number or null.
The optional replacer parameter is either a function that alters the way objects and arrays are stringified or an array of Strings and Numbers that act as a white list for selecting the object properties that will be stringified.
The optional space parameter is a String or Number that allows the result to have whitespace injected into it to improve human readability.
For detailed information see [ECMA11a(p.S15.12.3)].