Promise.resolve without arguments passed to

In the OpenUI5 code base, I came across this snippet:

// Wait until everything is rendered (parent height!) before reading/updating sizes.
// Use a promise to make sure
// to be executed before timeouts may be executed.
Promise.resolve().then(this._updateTableSizes.bind(this, true));

It looks like the built-in Promise function is used , without an argument passed to it resolve, which takes:

The argument that must be resolved by this promise. It can also be a promise or can then be resolved.

So, since it looks like the promise will simply resolve and call the callback right away then, perhaps an intent similar to :

var self = this;
setTimeout(function() {
    self._updateTableSizes.bind(self, true)
}, 0);

... basically, freeing up the JavaScript runtime loop to complete other actions (like rendering), and then back to the callback?

My question is:

Is this a common template? Best practice Are there any advantages / disadvantages for both?

+4
2

, Promise.resolve() undefined, . - - setTimeout, .

, , :

, .

- , . , , , ; , , , .

+5

polyfill: https://github.com/wicg/inert ( )

const newButton = document.createElement('button');
const inertContainer = document.querySelector('[inert]');
inertContainer.appendChild(newButton);
// Wait for the next microtask to allow mutation observers to react to the DOM change
Promise.resolve().then(() => {
expect(isUnfocusable(newButton)).to.equal(true);
});
+1

All Articles