Get Getter Function in Javascript

前端 未结 4 1477
时光取名叫无心
时光取名叫无心 2020-12-29 06:23

In JavaScript there is the possibility to create getters and setters the following way:

function MyClass(){
 var MyField;
 this.__defineGetter__(\"MyField\",         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 06:29

    Actually, __lookupGetter__ and __lookupSetter__ methods are deprecated. Instead of these you must use:

    /* __lookupGetter__ */
    Object.getOwnPropertyDescriptor(obj, 'MyField').get;
    
    /* __lookupSetter__ */
    Object.getOwnPropertyDescriptor(obj, 'MyField').set;
    

提交回复
热议问题