Make a summary every day, persistence is victory!

/** @date 2021-06-14 @description */Copy the code

One (sequence)

Instanceof is an operator that determines whether the constructor’s prototype is on the prototype chain of an instance object.

Ii (Use)

function Person() {
    this.type = 'person';
}
const p = new Person(); // Person {type: "person"}
p instanceof Person; // true
Copy the code

Iii. (Code Implementation)

function instanceOf(obj, ctor) { if(typeof obj ! == 'object' || typeof obj === null){ return false } let proto = Object.getPrototypeOf(obj); while(true) { if(proto === ctor.prototype) { return true } if(proto === null) { return false } proto = Object. GetPrototypeOf (proto)}} function Person(name) {this.name = name; } const p = new Person('E1e'); const obj = {}; const arr = []; instanceOf(p, Person); // true instanceOf(obj, Person); // false instanceOf(arr, Person); // false instanceOf(p, Object); // true instanceOf(arr, Array); // trueCopy the code

Iv. (Conclusion)

Wish you all a healthy Dragon Boat Festival!