You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.If Type(x) is different from Type(y), return false.
2.If Type(x) is Number, then
a. If x is NaN and y is NaN, return true.
b. If x is +0 and y is -0, return true.
c. If x is -0 and y is +0, return true.
d. If x is the same Number value as y, return true.
e. Return false.
3.Return SameValueNonNumber(x, y).
functionprocessAllUsers(){constsql="SELECT id FROM users";returndb.query(sql,[]).then(users=>users.reduce((lastPromise,user)=>{returnlastPromise.then(_=>processUser(user.id));},Promise.resolve()));}
You can compare the definition of Function.prototype.apply and Reflect.apply in the spec.
Basically they are equivalent, but there is a difference: if the arguments list is null or undefined, Function.prototype.apply will call the function with no arguments, and Reflect.apply will throw.
functionfunc(){returnarguments.length;}func.apply(void0,null);// 0Reflect.apply(func,void0,null);// TypeError: null is not a non-null object
Another difference is that, when you use func.apply, you assume
func is a Function instance, i.e. it inherits from Function.prototypefunc has no apply own property which would shadow Function.prototype.apply
But Reflect.apply doesn't require that. For example,
varobj=document.createElement('object');typeofobj;// "function" -- can be calledobj.apply;// undefined -- does not inherit from Function.prototypeReflect.apply(obj,thisArg,argList);// -- works properly
varfunc=a=>a;func.apply=a=>0;func.apply(void0,[123]);// 0 -- Function.prototype.apply is shadowed by an own propertyReflect.apply(func,void0,[123]);// 123 -- works properly