前端学习案例-你可能没见过的

获取对象的属性

  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"
            })
        

posted @ 2022-08-13 21:29  前端导师歌谣  阅读(23)  评论(0)    收藏  举报