JSFiddle - React, Tailwind, and code Playground
JavaScript
function ObjectStaticAssign(target, firstSource) {
// Steps 1-2.
var to = Object(target);
// Step 3.
if (arguments.length < 2)
return to;
// Step 4.
var i = 1;
do {
// Step 5.a-b, plus an unspecified flourish to skip null/undefined, so
// any site depending on agreed-upon (but not-yet-drafted) semantics
// from TC39 meeting minutes will work. (Yes, implausibly, such a site
// exists. See bug 1054426.)
var nextSource = arguments[i];
if (nextSource === null || nextSource === undefined)
continue;
var from = Object(nextSource);
// Step 5.c-d.
var keysArray = Object.keys(from); // WRONG!! Should call something like [[OwnPropertyKeys]]
// Steps 5.e-f.
var len = keysArray.length;
// Step 5.h.
var nextIndex = 0;
// Step 5.i (Modified a bit because we can't catch and store the
// actual Completion Record). Instead we have a marker object.
const MISSING = {};
var pendingException = MISSING;
// Step 5.j.
while (nextIndex < len) {
// Step 5.j.i-ii.
var nextKey = keysArray[nextIndex];
// Step 5.j.iii-v.
try {
// We'd like to use Object.propertyIsEnumerable here, but we
// can't, because if a property doesn't exist, it won't properly
// call getOwnPropertyDescriptor (important if |from| is a
// proxy).
var desc = Object.getOwnPropertyDescriptor(from, nextKey);
if (desc !== undefined && desc.enumerable)
to[nextKey] = from[nextKey];
} catch (e) {
if (pendingException === MISSING)
pendingException = e;
}
// Step 5.j.vi.
nextIndex++;
}
// Step 5.k.
if (pendingException !== MISSING)
throw...