banner
SlhwSR

SlhwSR

热爱技术的一名全栈开发者
github
bilibili

Implement instance of

First, instanceof is used to determine whether the prototype of a certain constructor exists on a certain instance object.

SmsClass instanceof Function ? "":SmsClass

Let's go straight to the code

export function instanceofFn(Left, Constructor) {
   const ConstructorP = Constructor.prototype;
   Left = Left.__proto__;
   // Keep looking up
   while (true) {
       if (Left === null) {
           return false;
       }
       if (Left === ConstructorP) {
           return true;
       }
       // Continue to search the prototype chain upwards
       Left = Left.__proto__;
   }
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.