gogoend / blog

blogs, ideas, etc.
MIT License
9 stars 2 forks source link

JavaScript实例类型判断 #32

Open gogoend opened 4 years ago

gogoend commented 4 years ago

typeof

instanceof

let instanceOf = function(l,r){
    let proto = l.__proto__,
        prototype = r.prototype

    while(proto){
        if(proto === prototype){
            return true
        } else {
            proto = proto.__proto__
        }
    }
    return false
}

Object.prototype.toString.call()