mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +00:00
Update std.js
This commit is contained in:
parent
f072522003
commit
8bcbdd5dcf
25
lib/std.js
25
lib/std.js
|
@ -70,17 +70,28 @@ global.GetResource = function(ResourceName) {
|
|||
return arguments.callee.caller.GetResource(ResourceName);
|
||||
}
|
||||
|
||||
// [lib/std] the time of `sleep()' function is not accuracy #34
|
||||
global.sleep = function(ms, callback) {
|
||||
var cur = Date.now();
|
||||
var end = cur + ms;
|
||||
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
WScript.Sleep(ms);
|
||||
if (typeof(callback) === "function") {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
if (typeof(callback) === "function") {
|
||||
setTimeout(callback, ms);
|
||||
while (cur < end) {
|
||||
WScript.Sleep(1);
|
||||
cur = Date.now();
|
||||
}
|
||||
end = Date.now();
|
||||
|
||||
if (typeof(callback) === "function")
|
||||
callback()
|
||||
;
|
||||
} else if (typeof(window) !== "undefined") {
|
||||
if (typeof(callback) === "function")
|
||||
setTimeout(callback, ms)
|
||||
;
|
||||
}
|
||||
|
||||
return end;
|
||||
};
|
||||
|
||||
global.CHR = function(ord) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user