📄 js.texi
字号:
@end table
Call method @var{method} from object @var{object} with arguments
@var{arguments}.
@c @cartouche
@example
callMethod (System.stdout, "writeln", ["Hello, world!"]);
@print{} Hello, world!
@end example
@c @end cartouche
@end defun
@c ----------------------------------------------------------------------
@node Native Objects, Extensions, Global Methods and Properties, NGS JavaScript Language
@section Native Objects
@menu
* Array::
* Boolean::
* Date::
* File::
* Directory::
* Function::
* Math::
* Number::
* Object::
* RegExp::
* String::
* System::
* VM::
@end menu
@c ----------------------------------------------------------------------
@node Array, Boolean, Native Objects, Native Objects
@subsection Array
@table @strong
@item Standard
@value{ECMA}
@item Incompatibilities
@itemize @bullet
@item The @code{toSource()} method is missing.
@item The constructor doesn't set the [[Prototype]] and [[Class]]
properties.
@end itemize
@end table
@defun Array (count)
@defunx Array (item@dots{})
Do exactly the same as the expression @code{new Array()} called with the
same arguments.
@end defun
@c --- Constructors -----------------------------------------------------
@deffn Constructor Array (count)
@deffnx Constructor Array (item@dots{})
Create a new array object. The first form creates a new array which
length is @var{count}. All items are set to value @samp{undefined}.
The second form creates an array that contains the given items as its
values.
@c @cartouche
@example
var a = new Array (5);
a.length;
@result{} 5
a.toString ();
@result{} undefined,undefined,undefined,undefined,undefined
a = new Array (1, 2, "hello");
a.length;
@result{} 3
a.toString ();
@result{} 1,2,hello
@end example
@c @end cartouche
@end deffn
@c --- Methods ----------------------------------------------------------
@defmethod Array concat (array[, @dots{}])
Create a new array object from the items of the called array object and
the argument arrays @var{array}, @dots{}. The contents of the argument
arrays are not modified.
@c @cartouche
@example
var a = new Array (1, 2, 3);
var b = a.concat (new Array (4, 5));
b.length;
@result{} 5;
b.toString ();
@result{} 1,2,3,4,5
@end example
@c @end cartouche
@end defmethod
@defmethod Array join ([glue])
Convert the array to a string. Individual items of the array are
combined with the string @var{glue}. If the argument @var{glue} is
omitted, string @code{","} is used.
@c @cartouche
@example
var a = new Array (1, 2, "three");
a.join ();
@result{} "1,2,three"
a.join ("-");
@result{} "1-2-three"
@end example
@c @end cartouche
@end defmethod
@defmethod Array pop ()
Remove the last item of the array. The method returns the item removed.
If the array is empty, value @code{undefined} is returned.
@c @cartouche
@example
a = new Array (1, 2, 3);
a.pop ();
@result{} 3
a.length;
@result{} 2
@end example
@c @end cartouche
@end defmethod
@defmethod Array push (any@dots{})
Insert items to the end of the array. The method returns the last item
pushed.
@c @cartouche
@example
a = new Array (1, 2);
a.push (7);
@result{} 7
a.push (7, 8, 9);
@result{} 9
System.print (a.join (", "), "\n");
@print{} 1, 2, 7, 7, 8, 9
@end example
@c @end cartouche
@end defmethod
@defmethod Array reverse ()
Reverse the array.
@c @cartouche
@example
a = new Array (1, 2, 3);
a.reverse ();
System.print (a.join (""), "\n");
@print{} 321
@end example
@c @end cartouche
@end defmethod
@defmethod Array shift ()
Remove item from the beginning of the array. The method returns the
item removed, or value @samp{undefined} if the array was empty.
@c @cartouche
@example
a = new Array (1, 2, 3);
a.shift ();
@result{} 1
@end example
@c @end cartouche
@end defmethod
@defmethod Array slice (start[, end])
Return a new array containing items between @var{start} (inclusively)
and @var{end} (exclusively) in the array. If the argument @var{end} is
negative, it is counted from the end of the array. If the argument
@var{end} is omitted, the method extract items from the position
@var{start} to the end of the array.
@c @cartouche
@example
a = new Array (1, 2, 3, 4, 5);
b = a.slice (1, 4);
System.print (b.join (", "), "\n");
@print{} 2, 3, 4
b = a.slice (1, -2);
System.print (b.join (", "), "\n");
@print{} 2, 3
b = a.slice (2);
System.print (b.join (", "), "\n");
@print{} 3, 4, 5
@end example
@c @end cartouche
@end defmethod
@defmethod Array splice (index, remove[, any@dots{}])
Modify array by removing old items and by inserting new ones. The
argument @var{index} specifies the index from which the array is
modified. The argument @var{remove} specifies how many old items are
removed. If the argument @var{remove} is 0, no old items are removed
and at least one new item must have been given. After the items are
removed, all remaining arguments are inserted after the position
@var{index}.
@c @cartouche
@example
var a = new Array (1, 2, 3);
a.splice (1, 1);
@result{} 1, 3
a.splice (1, 0, "new item");
@result{} 1, "new item", 2, 3
var a = new Array (1, 2, 3, 4);
a.splice (1, 2, "new item");
@result{} 1, "new item", 4
@end example
@c @end cartouche
@end defmethod
@defmethod Array sort ([sort_function])
Sort the array to the order specified by the argument function
@var{sort_function}. The comparison function @var{sort_function} takes
two arguments and it must return one of the following codes:
@table @code
@item -1
the first argument items is smaller than the second item (must come
before the second item)
@item 0
the items are equal
@item 1
the first argument item is bigger than the second item (it must come
after the second item)
@end table
@noindent If the argument @var{sort_function} is omitted, the items are
sorted to an alphabetical (lexicographical) order.
@c @cartouche
@example
a = new Array ("Jukka-Pekka", "Jukka", "Kari", "Markku");
a.sort ();
System.print (a, "\n");
@print{} Jukka,Jukka-Pekka,Kari,Markku
a = new Array (1, 2, 10, 20, 100, 200);
a.sort ();
System.stdout.writeln (a.toString ());
@print{} 1,10,100,2,20,200
@end example
@c @end cartouche
The sort method is stable in that sense that, if the comparison function
returns 0 for two items, their original order in the array is preserved.
For example, if a list of person objects is sorted first by their names,
and second by their ages, all persons with the same age will remain
sorted in an alphabetical order.
@c @cartouche
@example
function by_age (a, b)
@{
return a.age - b.age;
@}
function by_name (a, b)
@{
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
@}
function Person (name, age)
@{
this.name = name;
this.age = age;
@}
a = new Array (new Person ("Smith", 30),
new Person ("Jones", 31),
new Person ("Bob", 30),
new Person ("Chris", 29));
a.sort (by_name);
a.sort (by_age);
for (i in a)
System.print (i.name, ", ", i.age, "\n");
@print{} Chris, 29
@print{} Bob, 30
@print{} Smith, 30
@print{} Jones, 31
@end example
@c @end cartouche
@end defmethod
@defmethod Array toSource ()
@end defmethod
@defmethod Array toString ()
Convert the array to a string. The method converts each item of the
array to string and combines them with the string @code{","}.
@c @cartouche
@example
var a = new Array (1, "foo", 2, new Array (7, 8));
a.toString ();
@result{} 1,foo,2,7,8
@end example
@c @end cartouche
@end defmethod
@defmethod Array unshift (any@dots{})
Insert items @var{any}@dots{} to the beginning of the array. The method
returns the new length of the array.
@c @cartouche
@example
a = new Array (1, 2, 3);
System.print (a.unshift (7, 8, 9), "\n");
@print{} 6
@end example
@c @end cartouche
@end defmethod
@defcv Property Array length
The length of the array.
@c @cartouche
@example
var a = new Array (1, 2);
a.length;
@result{} 2
a.push (3, 4, 5);
a.length;
@result{} 5
@end example
@c @end cartouche
@end defcv
@c ----------------------------------------------------------------------
@node Boolean, Date, Array, Native Objects
@subsection Boolean
@table @strong
@item Standard
@value{ECMA}
@item Incompatibilities
@itemize @bullet
@item The constructor doesn't set the [[Prototype]] and [[Class]]
properties.
@end itemize
@end table
@defun Boolean ()
Return @code{false}.
@end defun
@defun Boolean (value)
@end defun
@c --- Constructors -----------------------------------------------------
@deffn Constructor Boolean ()
@deffnx Constructor Boolean (value)
Create a new boolean object. If no arguments are given, the returned
object will have value @samp{false}. If the argument @var{value} is
given, the initial value of the object is determined by the type of the
argument and its value. If the argument @var{value} is
@code{undefined}, @code{null}, @code{false}, @code{""} (an empty
string), or @code{0}, the value of the object will be @samp{false}. All
other values for the argument @var{value} will set the initial value of
the object to @samp{true}.
@end deffn
@defmethod Boolean toString ()
Return a string presentation of the boolean object. The method will
return string @code{"true"} or @code{"false"} according to the value of
the object.
@end defmethod
@defmethod Boolean valueOf ()
@end defmethod
@c ----------------------------------------------------------------------
@node Date, File, Boolean, Native Objects
@subsection Date
@table @strong
@item Standard
@value{ECMA}
@item Incompatibilities
XXX Check all methods and properties.
@end table
@defun MakeTime (hour, min, sec, ms)
@end defun
@defun MakeDay (year, month, date)
@end defun
@defun MakeDate (day, time)
@end defun
@defun TimeClip (time)
@end defun
@defun Date ([a1[, a2[, a3[, a4[, a5[, a6[, a7]]]]]]])
When the @code{Date} constructor is called as a function, it ignores
arguments @var{a1}@dots{}@var{a7} and returns the result of expression:
@example
new Date ().toString()
@end example
@end defun
@deffn Constructor Date ()
@deffnx Constructor Date ("@var{month} @var{day}, @var{year} @var{hours}:@var{minutes}:@var{seconds}")
@deffnx Constructor Date (@var{yr_num}, @var{mo_num}, @var{day_num})
@deffnx Constructor Date (@var{yr_num}, @var{mo_num}, @var{day_num}, @var{hr_num}, @var{min_num}, @var{sec_num})
@end deffn
@defop {Static Method} Date UTC (@var{year}, @var{month}, @var{day}, @var{hrs}, @var{min}, @var{sec})
@end defop
@defmethod Date format (format)
@end defmethod
@defmethod Date formatGMT (format)
@end defmethod
@defmethod Date getDate ()
@end defmethod
@defmethod Date getDay ()
@end defmethod
@defmethod Date getHours ()
@end defmethod
@defmethod Date getMinutes ()
@end defmethod
@defmethod Date getMonth ()
@end defmethod
@defmethod Date getSeconds ()
@end defmethod
@defmethod Date getTime ()
@end defmethod
@defmethod Date getTimezoneOffset ()
@end defmethod
@defmethod Date getYear ()
@end defmethod
@defmethod Date parse (string)
@end defmethod
@defmethod Date setDate (day)
@end defmethod
@defmethod Date setHours (hours)
@end defmethod
@defmethod Date setMinutes (minutes)
@end defmethod
@defmethod Date setMonths (months)
@end defmethod
@defmethod Date setSeconds (seconds)
@end defmethod
@defmethod Date setTime (time)
@end defmethod
@defmethod Date setYear (year)
@end defmethod
@defmethod Date toGMTString ()
@end defmethod
@defmethod Date toLocaleString ()
@end defmethod
@c ----------------------------------------------------------------------
@node File, Directory, Date, Native Objects
@subsection File
@table @strong
@item Standard
@value{JSREF}
@item Incompatibilities
XXX Check all methods and properties.
@end table
@deffn Constructor File (path)
@end deffn
@defop {Static Method} File byteToString (byte)
@end defop
@defop {Static Method} File chmod (path, mode)
@table @strong
@item Standard
@value{NGS}
@end table
Change permissions of file @var{path} to @var{mode}. The modes are
specifeid by or'ing the following values:
@table @code
@item 04000
set user ID on execution
@item 02000
set group ID on execution
@item 01000
sticky bit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -