Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Is there any list of polyfills for es3?

2022-11-03 09:06:39

I'm need polyfills for setTimeout (for non-block thread) and other, where I can find it?

Registered User
2022-11-03 12:48:06


setTimeout is technically not a part of JS specification. It's a part of window object, which is in its turn a part of browser. Or a part of node js api in case you're using node:)

There is an action called "doLater" which you can download here. It's not exactly setTimeout, but it allows you to run the delayed action.

I believe, the exact implementation would be sort of specific, since you probably also would like to pass the node object as a part of delayed function context. Basically, I guess, the idea is to create a global object/array which will store all delayed function calls along with the time they should be executed. On calling setTimeout you add these to the array. Then you register onframe event which takes current time, goes through the array and checks which of the actions can be already executed, executes them, and removes from the array.

For more polyfills you can check npm, which is a great source for any type of js code. For ex,:

I'll probably can check how this could be implemented tonight, in case you haven't find the answer by the time.

Registered User
2022-11-03 16:32:48

Ok, this seems to work:
var timers = [];

// define setTimeout
function setTimeout(fn, ms, args) {
var executeAt = (new Date()).getTime() + ms;
fn: function () {
return fn.apply(this, args);
executeAt: executeAt

// register onFrameEvent which checks for
// the functions which should be called
ccbRegisterOnFrameEvent(function () {
var now = (new Date()).getTime();
for (var i = 0; i < timers.length; i++) {
if (timers[i].executeAt <= now) {
// This array remove method is slow for small arrays
// but I guess you can get OutOfMemory otherwise
timers.splice(i, 1);

Setup example:

Notice, that if you need to pass any data you should use args arguments for that - it should be an array. I also didn't test what will happen in case you're not providing it, so if it doesn't work just put empty array there.

Usage example would be:
var node = ccbGetCurrentNode();

setTimeout(function(node, text) {
ccbSetSceneNodeProperty(node, 'Text', text);
}, 1500, [node, 'a text from the script']);

2022-11-03 20:05:32

thank you for answer, i'm tried your code.

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Internation?l" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact