天天看點

前端學習案例-你可能沒見過的

擷取對象的屬性

var obj={
            get a(){
                return Math.random()>=0.5?1:0
            }
        }
        const round=obj.__lookupGetter__("a")
        console.log(round)
        //拿出 a(){
            // return Math.random()>=0.5?1:0
            // }      

擷取對象的屬性

const round1=Object.getOwnPropertyDescriptors(obj,"a").get;
            console.log(round)
            //拿出 a(){
            // return Math.random()>=0.5?1:0
            // }      
//底層拿的東西
            obj.__defineGetter__("a",function(){
                return "get a"
            })