ES6 Reflect对象

2018-09-26  本文已影响0人  ITgecko
Reflect对象介绍
let obj = {}, str = ""
Reflect.__proto__ === Object.prototype // true
obj.__ proto__ === Reflect.__proto__ // true
str.__proto__ // String {"", mulReplace: ƒ, format: ƒ, tmpl: ƒ, contains: ƒ, dbc2sbc: ƒ, …}
Reflect函数与Object.*的区别
函数行为API
let obj = {a:1}

Reflect.has(obj, 'a')
// 相当于
'a' in obj 

Reflect.get(obj, 'a')
// 相当于
obj.a

Reflect.set(obj, 'b', 2)
// 相当于
obj.b = 2

Reflect.deleteProperty(obj, 'b')
// 相当于
delete obj.a

Reflect.construct(String, ['str'])
// 相当于
new String('str')
上一篇 下一篇

猜你喜欢

热点阅读