Defining Setter/Getter for an unparented local variable: impossible?

前端 未结 4 1948
陌清茗
陌清茗 2020-12-25 10:54

There\'s a few previous questions on StackOverflow questioning how one goes about accessing local variables via the scope chain, like if you wanted to reference a local vari

4条回答
  •  情歌与酒
    2020-12-25 11:28

    I don't know if this answers your question but this works:

    Object.defineProperty(window, 'prop', {
    get: function () {
        alert('you just got me')
    },
    
    set: function (val) {
        alert('you just set me')
    },
    
    configurable: true});
    

提交回复
热议问题