当前位置:网站首页>ES6 reflect object
ES6 reflect object
2022-04-22 21:49:00 【shaobohong】
Keep the default behavior
Reflect Object method and Proxy Object's methods correspond one to one , As long as it is Proxy Object method , You can be in Reflect Find the corresponding method on the object . This makes Proxy Object can easily call the corresponding Reflect Method , Complete the default behavior , As the basis for modifying behavior . in other words , No matter Proxy How to modify the default behavior , You can always be in Reflect Get default behavior on
var obj = {}
var proxy = new Proxy(obj, {
set: function(target, key, val, proxy){
var success = Reflect.set(target, key, val, proxy);
if (success) {
console.log(`set '${key}' = '${val}' success`);
} else {
console.log(`set '${key}' = '${val}' error`);
}
},
get: function(target, key, proxy) {
console.log(`get '${key}'`);
return Reflect.get(target, key, proxy);
}
})
proxy.name = 'new name';
proxy.name;
console.dir(obj)

Static methods
- Reflect.apply(target, thisArg, args)
- Reflect.construct(target, args)
- Reflect.get(target, name, receiver)
- Reflect.set(target, name, value, receiver)
- Reflect.defineProperty(target, name, desc)
- Reflect.deleteProperty(target, name)
- Reflect.has(target, name)
- Reflect.ownKeys(target)
- Reflect.isExtensible(target)
- Reflect.preventExtensions(target)
- Reflect.getOwnPropertyDescriptor(target, name)
- Reflect.getPrototypeOf(target)
- Reflect.setPrototypeOf(target, prototype)
// get attribute
var obj1 = {name: 'obj1 name'}
Reflect.get(obj1, 'name');
// get attribute
var obj2 = {name: 'obj2 name'}
Reflect.set(obj2, 'name', 'new name');// new name
// Determine whether there are attributes
var obj3 = {name: 'obj3 name'}
Reflect.has(obj3, 'name'); // true
'name' in obj3; // true
// Delete attribute
var obj4 = {name: 'obj4 name'}
Reflect.deleteProperty(obj4, 'name');
delete obj4.name;
// Constructors
function genObj(name) {
this.name = name;
}
var obj5 = Reflect.construct(genObj, ['obj5 name']);
var obj5 = new genObj('obj5 name');
// Get the object's __proto__ Prototype
var obj6 = {name: 'obj6 name'}
Reflect.getPrototypeOf(obj6) === obj6.__proto__; // true
// Set the __proto__ Prototype
var obj7 = {name: 'obj7 name'}
console.log(obj7.__proto__ === Array.prototype); // false
Reflect.setPrototypeOf(obj7, Array.prototype);
console.log(obj7.__proto__ === Array.prototype); // true
// Reflect.apply()
var obj8 = {name: 'obj8 name'}
// Intercept
var obj9 = {name: 'obj9 name'}
Reflect.defineProperty(obj9, 'name', {
set: function(){},
get: function(){}
})
// replace Object.defineProperty()
// Gets the description object of the specified property of the object
var desc = Reflect.getOwnPropertyDescriptor(obj9, 'name');
console.dir(desc)
// Whether it can be extended 、 Non scalable
var obj10 = {name: 'obj10 name'}
Reflect.isExtensible(obj10);// true
Reflect.preventExtensions(obj10);
Reflect.isExtensible(obj10)// false
// Get all properties
var obj11 = {name: 'obj11 name', age: '1', type: 'object'}
Reflect.ownKeys(obj11);
版权声明
本文为[shaobohong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221708110498.html
边栏推荐
- Solving chrome cross domain problems - cross domain series
- 几个小 shell 脚本实战学习
- php中302指的是什么
- Unstable sorting (selection, fast)
- . net core uses iasyncexceptionfilter to capture global exceptions and return information uniformly
- Drop down options under playwright operation select
- Uclibc is different from glibc
- Autodesk products cannot install the solution
- Mailbox format test
- Online yaml to XML tool
猜你喜欢
随机推荐
Thread communication mechanism: shared memory VS message passing
短视频内容理解与生成技术在美团的创新实践
MATLAB 基本命令
Navicat for MySQL 连接 Docker中运行的Mysql出现1251- Client does not support authentication protocol 错误
How to configure the digital portal within 10 minutes and present it in a centralized, unified and all-round way
Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
企评家为政府打造决策支撑平台
Tool class xmlutil (parse and return soap and XML messages to obtain the value of the target node)
Practical learning of several small shell scripts
How to realize guessing numbers games in C language
Adobe series error code solutions summary
[browser] the translation provided by Google browser is invalid
[advanced level of C language] an article takes you to recognize structure, enumeration and union
Browser HTTP cache related knowledge
Apache configuration multiport
Pushing hand of industrial Internet innovation iteration
Leaflet修改地图中心点定位
The latest version of watermark + takeout CPS applet source code
C randomly obtains one from list or string
CSV column extract column extraction





![[IPTV]华为悦盒EC6108V9A刷机](/img/96/40eed4fddf627c3749d0f3bb3fc8f6.png)


