mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
510 B
28 lines
510 B
/*
|
|
* Compare slice() against substr() and substring().
|
|
*/
|
|
|
|
var str = new String('abcdefghij');
|
|
|
|
/*===
|
|
10
|
|
de
|
|
de de
|
|
defgh fgh
|
|
===*/
|
|
|
|
try {
|
|
print(str.length);
|
|
|
|
// slice won't swap arguments like substring()
|
|
print(str.slice(3, 5), str.slice(5, 3));
|
|
print(str.substring(3, 5), str.substring(5, 3));
|
|
|
|
// substring() takes a start and end offset as arguments, but
|
|
// substr() takes a start offset and *length*
|
|
print(str.substr(3, 5), str.substr(5, 3));
|
|
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|
|
|