__defineSetter__、__defineGetter__、__lookupSetter__、__lookupGetter__

本文通过一个JavaScript示例展示了如何使用属性存取器来设置和获取对象属性。具体包括了getname和setname方法的实现,以及如何利用__lookupSetter__和__lookupGetter__方法来操作这些存取器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var t = {
        //主要是要注意这里的写法,没有':'也没有'function'
	get name(){
		return this.x
	},
	set name(x){
		this.x = x
	}
};
//t.__defineSetter__("name",function(x){this.x=x})
//t.__defineGetter__("name",function(){return this.x})
    
t.__lookupSetter__("name")("aluckyman");
console.log("***************");
console.log(t.__lookupGetter__("name")());
console.log("***************");

 mark 一下,以前从没去关注这个。。

为啥自定义校验// 提取出来的密码校验函数 const validatePasswordMatch = (rule: any, value: string, callback: Function) => { console.log('rule:',rule) console.log('value:',value); console.log('callback:',callback); if (!formModel.value.password) { callback(new Error('密码不能为空')) } else if (value !== formModel.value.password) { callback(new Error('两次密码输入不一致')) } else { callback() // 校验通过 } }rule: 123 forgetPsw.vue:51 value: Proxy(Object) {trigger: 'blur', validator: ƒ}[[Handler]]: MutableReactiveHandler[[Target]]: Objecttrigger: "blur"validator: (rule, value, callback) => {…}length: 3name: "validatePasswordMatch"arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at validatePasswordMatch.invokeGetter (<anonymous>:3:28)]caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at validatePasswordMatch.invokeGetter (<anonymous>:3:28)][[FunctionLocation]]: forgetPsw.vue:49[[Prototype]]: ƒ ()[[Scopes]]: Scopes[3][[Prototype]]: Objectconstructor: ƒ 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__()[[IsRevoked]]: false forgetPsw.vue:52 callback: undefined
03-23
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值