Update std.js

This commit is contained in:
Namhyeon Go 2022-02-08 18:55:29 +09:00 committed by GitHub
parent 6aa800f692
commit cb6e0ba171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,14 +99,14 @@ global.sleep = function(ms, callback) {
return { 'ms': end, 'handler': handler };
};
global.repeat = function(ms, callback, error) {
global.doRepeat = function(ms, callback, error) {
var handler = null;
var cur = Date.now();
var end = cur + ms;
if (typeof WScript !== "undefined") {
while (cur < end) {
while (ms === true ? true : (cur < end)) {
try {
sleep(callback());
} catch (e) {
@ -117,13 +117,44 @@ global.repeat = function(ms, callback, error) {
end = Date.now();
} else if (typeof window !== "undefined") {
if (typeof callback === "function")
handler = setInterval(callback, ms)
handler = setInterval(callback, ms);
;
}
return { 'ms': end, 'handler': handler };
};
global.range = function() {
var args = arguments;
var N = [], start, end, step;
switch(args.length) {
case 3:
start = args[0];
end = args[1];
step = args[2];
break;
case 2:
start = args[0];
end = args[1];
step = 1;
break;
case 1:
start = 0;
end = args[0];
step = 1;
break;
}
for (var i = start; i < end; i = i + step)
N.push(i)
;
return N;
};
global.CHR = function(ord) {
return String.fromCharCode(ord);
};