防腐木用什么名字做网站,wordpress浏览记录,wordpress 324错误,广西茶叶学会 网站建设定义
Proxy
为开发者提供了拦截并向基本操作嵌入额外行为的能力。具体的说#xff0c;可以给目标对象定义一个关联的代理对象#xff0c;而这个代理对象可以作为抽象的目标对象来使用。在对目标对象的各种操作影响目标对象之前#xff0c;可以在代理对象中对这些操作加以控…定义
Proxy
为开发者提供了拦截并向基本操作嵌入额外行为的能力。具体的说可以给目标对象定义一个关联的代理对象而这个代理对象可以作为抽象的目标对象来使用。在对目标对象的各种操作影响目标对象之前可以在代理对象中对这些操作加以控制。用于修改某些操作的默认行为等同于在语言层面做出修改所以属于中“元编程”即对编程语言进行编译。可以理解成在目标对象前架设一个“拦截”层外界对该对象的访问都必须先通过这层拦截。通过调用new Prosy(),你可以创建一个代理用来替代另一个对象这个代理对目标对象进行了虚拟因此该代理与该目标对象表面上可以被当做同一个对象来对待。
关键词
创建代理对象是一个新对象其他对象只能代理对象
Reflect
将object对象的一些明显属于语言内部的方法比如Object.defineProperty放到Reflect上。现阶段某些方法同时在Object和Reflect上部署未来的新方法只会在Reflect上部署。从Reflect可以拿到语言内部的方法。修改某些方法的返回值让其变得合理Reflect对象的方法与Proxy对象的方法一一对应
方法
Reflect.get(target,name,receiver) 查找并返回target的name属性没有则返回undefined
Reflect.set(target,name,value,receiver) 对象属性的设置返回一个布尔值
Reflect.has(target,propKey) propKey in proxy 操作返回一个boolean值
Reflect.deleteProperty(target,name) 等同于delete obj[name]用于删除对象属性
Reflect.construct(target,args) 等同于new target(...args)这提供了一种不使用new来调用构造函数的方法
Reflect.getPrototypeOf(target) 用于读取对象的__proto__属性对应Object.getPrototypeOf(obj)
Reflect.setPrototypeOf(target,prototype) 用于设置目标对象的原型prototype,对应Object.setPrototypeOf(obj,newProto)方法返回一个boolean值表示是否设置成功
Reflect.apply(target,thisArg,args) 等同于Function.prototype.apply.call(func,thisArg,args),用于绑定this对象后执行给定函数
Reflect.defineProperty(target,name,desc) 方法基本等同于Object,defineProperty,用来为对象定义属性未来后者会被逐渐替代
Reflect.getOwnPropertyDescriptor(target,name) 基本等同于Object.getOwnPropertyDescriptor用于得到指定属性的描述对象将来会替代掉后者
Reflect.isExtensible 对应Object.isExtensible返回一个布尔值表示当前对象是否可扩展。
Reflect.preventExtensions 对应Object.preventExtensions方法用于让一个对象变为不可扩展。它返回一个布尔值表示是否操作成功。
Reflect.ownKeys 方法用于返回对象的所有属性基本等同于Object.getOwnPropertyNames与Object.getOwnPropertySymbols之和
数组倒序访问
var arr [1, 2, 3, 4]
var proxy new Proxy(arr, {get(target, propKey, receiver) {let nPropKey parseInt(propKey as string) //解析字符串返回整数if (nPropKey 0) {if (Math.abs(nPropKey) target.length) { // 返回绝对值return target[target.length nPropKey]} else {return 访问越界}}return Reflect.get(target, propKey, receiver)}
})
console.log(proxy[-2])
console.log(proxy[-20])实现观察者模式
const queuedObserverList:SetFunction new Set()
const observe (fn:Function) {queuedObserverList.add(fn)
}
const observable (obj) new Proxy(obj, {set(target, key, value, receiver) {queuedObserverList.forEach((fun) fun())return Reflect.set(target, key, value, receiver)}
})const person observable({ name: hello, age: 11 })
function print() {console.log(${person.name}--${person.age})
}
observe(print)
person.name hikeyof优化
module A {type Person {name: string,age: number,sex: number}const proxy (object: any, key: any) {return new Proxy(object, {get(target, prop, receiver) {console.log(get)return Reflect.get(target, prop, receiver)},set(target, prop, value, receiver) {console.log(set)return Reflect.set(target, prop, value, receiver)}})}// const logAccess (object: Person, key: name | age | sex) {// return proxy(object, key)// }const logAccess T(object: T, key: keyof T) {return proxy(object, key)}let woman: Person logAccess({name: orange,sex: 0,age: 18}, age)woman.age 16console.log(woman)
} 文章转载自: http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.pwhjr.cn.gov.cn.pwhjr.cn http://www.morning.hpcpp.cn.gov.cn.hpcpp.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.dzqr.cn.gov.cn.dzqr.cn http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn http://www.morning.wcqkp.cn.gov.cn.wcqkp.cn http://www.morning.sskns.cn.gov.cn.sskns.cn http://www.morning.mhpmw.cn.gov.cn.mhpmw.cn http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn http://www.morning.rycd.cn.gov.cn.rycd.cn http://www.morning.npbnc.cn.gov.cn.npbnc.cn http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn http://www.morning.xltwg.cn.gov.cn.xltwg.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.pbsqr.cn.gov.cn.pbsqr.cn http://www.morning.tftw.cn.gov.cn.tftw.cn http://www.morning.hkng.cn.gov.cn.hkng.cn http://www.morning.wschl.cn.gov.cn.wschl.cn http://www.morning.ktmpw.cn.gov.cn.ktmpw.cn http://www.morning.czcbl.cn.gov.cn.czcbl.cn http://www.morning.cpktd.cn.gov.cn.cpktd.cn http://www.morning.fbzdn.cn.gov.cn.fbzdn.cn http://www.morning.ztjhz.cn.gov.cn.ztjhz.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.hnkkm.cn.gov.cn.hnkkm.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.bftr.cn.gov.cn.bftr.cn http://www.morning.ypbdr.cn.gov.cn.ypbdr.cn http://www.morning.ksgjn.cn.gov.cn.ksgjn.cn http://www.morning.fwzjs.cn.gov.cn.fwzjs.cn http://www.morning.grryh.cn.gov.cn.grryh.cn http://www.morning.wjrq.cn.gov.cn.wjrq.cn http://www.morning.lqgtx.cn.gov.cn.lqgtx.cn http://www.morning.rbzht.cn.gov.cn.rbzht.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.lcplz.cn.gov.cn.lcplz.cn http://www.morning.rlkgc.cn.gov.cn.rlkgc.cn http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.ggfdq.cn.gov.cn.ggfdq.cn http://www.morning.sloxdub.cn.gov.cn.sloxdub.cn http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.yjdql.cn.gov.cn.yjdql.cn http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.hpxxq.cn.gov.cn.hpxxq.cn http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.chhhq.cn.gov.cn.chhhq.cn http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.kdhrf.cn.gov.cn.kdhrf.cn http://www.morning.rbjth.cn.gov.cn.rbjth.cn http://www.morning.mkydt.cn.gov.cn.mkydt.cn http://www.morning.tkflb.cn.gov.cn.tkflb.cn http://www.morning.slqgl.cn.gov.cn.slqgl.cn http://www.morning.bwmq.cn.gov.cn.bwmq.cn http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.ydgzj.cn.gov.cn.ydgzj.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.qsy37.cn.gov.cn.qsy37.cn http://www.morning.qgghj.cn.gov.cn.qgghj.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.qngcq.cn.gov.cn.qngcq.cn http://www.morning.wbyqy.cn.gov.cn.wbyqy.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.ztqj.cn.gov.cn.ztqj.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.lcqrf.cn.gov.cn.lcqrf.cn http://www.morning.gkdqt.cn.gov.cn.gkdqt.cn