特殊函数

var i = 0
Object.defineProperty(window,'x',{
    get(){
        return ++i
    }
})
function Fn(){
    if(this.constructor == Fn){
        this.id =i
    }else{
        let obj = {}
        obj.__proto__ = Fn.prototype
        obj.id = i
        return obj
    }
}
function Fn(){
    !Fn.prototype.n && (Fn.prototype.n = 0)
    if(new.target == Fn){
        this.id = ++Fn.prototype.n
    }else{
        let obj = {}
        obj.__proto__ = Fn.prototype
        obj.id = ++Fn.prototype.n
        return obj
    }
}
posted @ 2020-07-17 19:23  671_MrSix  阅读(128)  评论(0编辑  收藏  举报