关于__defineGetter__ 和__defineSetter__的说明

Getter是一种获取一个属性的值的方法,Setter是一种设置一个属性的值的方法。可以为任何预定义的核心对象或用户自定义对象定义getter和setter方法,从而为现有的对象添加新的属性。 
有两种方法来定义Getter或Setter方法: 

在对象初始化时定义  
在对象定义后通过Object的__defineGetter__、__defineSetter__方法来追加定义  
在使用对象初始化过程来定义Getter和Setter方法时唯一要做的事情就是在getter方法前面加上“get”,在setter方法前面加上“set”。 
还有一点要注意的就是getter方法没有参数,setter方法必须有一个参数,也就是要设置的属性的新值。 
例如: 

 

Getter是一种获取一个属性的值的方法,Setter是一种设置一个属性的值的方法。可以为任何预定义的核心对象或用户自定义对象定义getter和setter方法,从而为现有的对象添加新的属性。 
有两种方法来定义Getter或Setter方法: 

在对象初始化时定义  
在对象定义后通过Object的__defineGetter__、__defineSetter__方法来追加定义  
在使用对象初始化过程来定义Getter和Setter方法时唯一要做的事情就是在getter方法前面加上“get”,在setter方法前面加上“set”。 
还有一点要注意的就是getter方法没有参数,setter方法必须有一个参数,也就是要设置的属性的新值。 
例如: 
2 400 index.vue:399 QiniuRequestError {name: 'RequestError', message: 'xhr request failed, code: 400 response: {"error":"…field CompleteMultipart.mimeType of type string"}', stack: 'Error\n at QiniuRequestError.QiniuError (webpack…node_modules/qiniu-js/esm/utils/helper.js:248:24)', code: 400, reqId: 'Mm0AAACDvvroC2YX', …} code : 400 data : error : "json: cannot unmarshal array into Go struct field CompleteMultipart.mimeType of type string" [[Prototype]] : Object constructor : ƒ Object() hasOwnProperty : ƒ hasOwnProperty() isPrototypeOf : ƒ isPrototypeOf() propertyIsEnumerable : ƒ propertyIsEnumerable() toLocaleString : ƒ toLocaleString() toString : ƒ toString() valueOf : ƒ valueOf() __defineGetter__ : ƒ __defineGetter__() __defineSetter__ : ƒ __defineSetter__() __lookupGetter__ : ƒ __lookupGetter__() __lookupSetter__ : ƒ __lookupSetter__() __proto__ : (...) get __proto__ : ƒ __proto__() set __proto__ : ƒ __proto__() isRequestError : true message : "xhr request failed, code: 400 response: {\"error\":\"json: cannot unmarshal array into Go struct field CompleteMultipart.mimeType of type string\"}" name : "RequestError" reqId : "Mm0AAACDvvroC2YX" stack : "Error\n at QiniuRequestError.QiniuError (webpack-internal:///./node_modules/qiniu-js/esm/errors/index.js:47:22)\n at new QiniuRequestError (webpack-internal:///./node_modules/qiniu-js/esm/errors/index.js:55:28)\n at xhr.onreadystatechange (webpack-internal:///./node_modules/qiniu-js/esm/utils/helper.js:248:24)" [[Prototype]] : QiniuError constructor : ƒ QiniuRequestError(code, reqId, message, data) [[Prototype]] : Object
最新发布
06-07
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值