ES6锛堝崄涓€锛塒roxy鍜孯eflect

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ES6锛堝崄涓€锛塒roxy鍜孯eflect相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/strong' title='strong'>strong   replace   style   绛変簬   key   monitor   鏃ユ湡   time   杩斿洖   

Proxy

let obj = 
  time: 鈥?019-01-01鈥?span style="color: #000000;">,
  name: 鈥榬onle鈥?span style="color: #000000;">

let monitor = new Proxy(obj, 
  // 鎷︽埅瀵硅薄灞炴€х殑璇诲彇
  get (target, key) 
    return target[key].replace(鈥?019鈥? 鈥?020鈥?span style="color: #000000;">)
  ,
  // 鎷︽埅瀵硅薄璁剧疆灞炴€?/span>
  set (target, key, value) 
    // 鍙湁key绛変簬name鎵嶄慨鏀?/span>
    if (key === 鈥榥ame鈥?span style="color: #000000;">) 
      return Reflect.set(target, key, value)
     else 
      return target[key]
    
  ,
  // 鎷︽埅 key in object鎿嶄綔
  has (target, key) 
    if (key === 鈥榥ame鈥?span style="color: #000000;">) 
      return target[key]
     else 
      return false
    
  ,
  // 鎷︽埅delete
  deleteProperty (target, key) 
    if (key.indexOf(鈥?鈥?span style="color: #000000;">)) 
      delete target[key]
      return true
     else 
      return target[key]
    
  ,
  // 鎷︽埅Object.keys
  // Object.getOwnPropertySymbols
  // Object.getOwnPropertyNames
  ownKeys (target) 
    return Object.keys(target).filter(item => item !== 鈥榯ime鈥?span style="color: #000000;">)
  
)
// 2020-01-01
console.log(鈥榞et鈥?span style="color: #000000;">, monitor.time)
monitor.time = 鈥?030鈥?span style="color: #000000;">
monitor.name = 鈥榢aka鈥?
// 鍙湁name琚慨鏀? kaka
console.log(鈥榮et鈥?span style="color: #000000;">, monitor, monitor.name)

console.log(鈥榟as鈥? 鈥榥ame鈥?in monitor, 鈥榯ime鈥?in monitor)
// // 鍒犻櫎鎺夋棩鏈?/span>
// delete monitor.time
// console.log(鈥榙elete鈥? monitor)

// 杩斿洖涓嶇瓑浜巏ey涓嶇瓑浜巘ime鐨勫厓绱?/span>
console.log(鈥榦wnKeys鈥?span style="color: #000000;">, Object.keys(monitor))


Reflect 璺焢roxy浠g悊绫讳技锛屾柟娉曞睘鎬ч兘涓€鏍?/strong>

let obj = 
  time: 鈥?019-01-01鈥?span style="color: #000000;">,
  name: 鈥榬onle鈥?span style="color: #000000;">


console.log(Reflect.get(obj, 鈥榯ime鈥?span style="color: #000000;">))
Reflect.set(obj, 鈥榥ame鈥? 鈥榢aka鈥?span style="color: #000000;">)
console.log(obj)
console.log(Reflect.has(obj, 鈥榥ame鈥?)

 

以上是关于ES6锛堝崄涓€锛塒roxy鍜孯eflect的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot锛堝崄涓€锛塕edis闆嗘垚浠嶥ocker瀹夎鍒板垎甯冨紡Session鍏变韩

Request鍜孯esponse

鏁版嵁缁撴瀯瀹為獙涔嬫爤涓庨槦鍒楀崄涓€锛歳efresh鐨勫仠杞﹀満

Roxy-Wi 远程命令执行漏洞 CVE-2022-31137

Roxy-Wi 远程命令执行漏洞 CVE-2022-31137