#js #interview #promise
Analysis: Use the Promise.all principle to synchronize the Promise state through the counter and result array.
Please open Telegram to view this post
VIEW IN TELEGRAM
#js #interview #instanceof
The instanceof operator in JavaScript can be used to determine whether an object is an instance of another object. However, the instanceof operator has some limitations, such as:
π₯«The instanceof operator can only determine objects directly connected to the prototype chain.
π―The instanceof operator cannot detect objects with cyclic prototype chains.
Therefore, the above code provides a more general instanceof function that can determine the relationship between any two objects.
The implementation principle of this function is:
πThe function instanceof receives two parameters: left and right.
π₯First, the code checks to see if the number of parameters is 2, and if not, throws an error.
π₯Next, the code checks whether the left operand left is null. If so, it returns false directly, because null cannot be an instance of any object.
π§Then, the code checks whether the type of the left operand left is an object. If not, it returns false directly, because only objects can be instances of the constructor.
π₯Next, the code uses Object.getPrototypeOf() to obtain the prototype of the left operand left and assigns it to the variable proto.
πIn a loop, the code continues to traverse protoβs prototype chain until proto is null.
π₯In the loop, the code checks whether the prototype of the right operand right is equal to the current proto. If they are equal, it means that the left operand left is an instance of the right operand right and returns true.
π If no matching prototype is found at the end of the loop, that is, proto is null, it means that the left operand left is not an instance of the right operand right, and false is returned.
Please open Telegram to view this post
VIEW IN TELEGRAM