当前位置:网站首页>JS reflect
JS reflect
2022-06-30 04:09:00 【Runqing】
Reflect Is a built-in object , It provides interception JavaScript How to operate , yes ES6 New... For manipulating objects API.
Reflect It's not a function object , So it's not constructable .
Reflect All properties and methods of are static .
significance
- At this stage , Some methods are at the same time Object and Reflect Object , New methods in the future will only be deployed in Reflect On the object .
- Modify some Object method , Make it more standardized . Such as Object.defineProperty(obj, name, desc) When properties cannot be defined , It throws an error , and Reflect.defineProperty(obj, name, desc) Will return false.
- Give Way Object Operations become function behaviors .
- 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 .
a key
Method
Reflect Object currently has 13 A static method .
// To call a function , At the same time, you can pass in an array as the call parameter .
Reflect.apply(target, thisArg, args)
// On the constructor new operation , Equivalent to execution new target(...args).
Reflect.construct(target, args)
// Get the value of an attribute on the object , Be similar to target[name]. If this property is not available , Then return to undefined.
Reflect.get(target, name, receiver)
// Functions that assign values to properties . Return to one Boolean, If the update is successful , Then return to true.
Reflect.set(target, name, value, receiver)
// Reflect.defineProperty The method is basically equivalent to Object.defineProperty, Define a new property directly on an object , Or modify the existing properties of an object , The difference is ,Object.defineProperty Return this object . and Reflect.defineProperty Will return a Boolean value .
Reflect.defineProperty(target, name, desc)
// As a function delete The operator , Equivalent to execution delete target[name].
Reflect.deleteProperty(target, name)
// Determine whether an object has an attribute , and in Operator It has exactly the same function .
Reflect.has(target, name)
// Return a containing all its own attributes ( Does not contain inherited properties ) Array of .( Be similar to Object.keys(), But it won't be affected enumerable influence , Object.keys Returns a string array of all enumerable properties ).
Reflect.ownKeys(target)
// Determine whether an object is extensible ( Can I add new properties to it ), Be similar to Object.isExtensible(). Returns a that indicates whether a given object is extensible Boolean .(Object.seal or Object.freeze Methods can mark an object as non extensible .)
Reflect.isExtensible(target)
// Make an object non extensible , That is, you can never add new attributes .
Reflect.preventExtensions(target)
// If the attribute exists in the object , If the specified property exists on the object , Then its property descriptor object (property descriptor), Otherwise return to undefined. Be similar to Object.getOwnPropertyDescriptor().
Reflect.getOwnPropertyDescriptor(target, name)
// Returns the prototype of the specified object . Be similar to Object.getOwnPropertyDescriptor().
Reflect.getPrototypeOf(target)
// Set the object prototype function . Return to one Boolean, If the update is successful , Then return to true. If target No Object , or prototype Neither the object nor null, Throw a TypeError abnormal .
Reflect.setPrototypeOf(target, prototype)
Use
// Reflect.apply
var obj1 = {
};
Reflect.apply(Math.floor, obj1, [1.88]) // 1;
// Reflect.construct
const obj2 = Reflect.construct(Date, [2021, 3, 1])
// Reflect.get
var obj3 = {
x: 1, y: 2 };
Reflect.get(obj3, "x"); // 1
// Reflect.set
var obj4 = {
};
Reflect.set(obj4, "prop", "value"); // true
// Reflect.defineProperty(
const obj5 = {
};
Reflect.defineProperty(obj5, 'property', {
value: 666,
writable: false
}); // true
// Reflect.deleteProperty
var obj6 = {
x: 1, y: 2 };
Reflect.deleteProperty(obj6, "x"); // true
obj; // { y: 2 }
// Reflect.has
const obj7 = {
x: 0}
Reflect.has(obj7, "x"); // true
// Reflect.ownKeys
const obj8 = {
z: 3, y: 2, x: 1}
Reflect.ownKeys(obj8); // [ "z", "y", "x" ]
// Reflect.isExtensible
var obj9 = {
};
Reflect.isExtensible(obj9); // true
// Reflect.preventExtensions
var obj10 = {
};
Reflect.isExtensible(obj10); // true
Reflect.preventExtensions(obj10);
Reflect.isExtensible(obj10); // false
// Reflect.getOwnPropertyDescriptor
const obj11 = {
x: "hello"}
Reflect.getOwnPropertyDescriptor(obj11, "x");
// {value: "hello", writable: true, enumerable: true, configurable: true}
// Reflect.getPrototypeOf
var obj12 = {
};
Reflect.getPrototypeOf(obj12); // Equate to Object.prototype
// Reflect.setPrototypeOf
var obj13 = {
};
Reflect.setPrototypeOf(obj13, null); // true
边栏推荐
- Pig-Latin (UVA492)
- 第九天 脚本與資源管理
- 找到接口在表单里加参数
- EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
- Troubleshoot abnormal video playback problems in public network deployment based on Haikang ehomedemo tool
- Day 12 advanced programming techniques
- [Thesis reading | deep reading] role2vec:role based graph embeddings
- Solutions for project paths
- SQL server2005中SUM函数中条件筛选(IF)语法报错
- Sql语句遇到的错误,求解
猜你喜欢

学校实训要做一个注册页面,要打开数据库把注册页面输入的内容存进数据库但是

About manipulator on Intelligent Vision Group

Green new power and "zero" burden of computing power -- JASMINER X4 series is popular

Solve the problem of Navicat connecting to the database

El upload Upload file (Manual upload, Automatic upload, upload progress)

关于智能视觉组上的机械臂

基于ROS的SLAM建图、自动导航、避障(冰达机器人)

Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)

如何利用FME 创建自己的功能软件

el-upload上傳文件(手動上傳,自動上傳,上傳進度)
随机推荐
Educoder group purchase suspension box page production
解决navicat连接数据库遇到的问题
Magical Union
El upload Upload file (Manual upload, Automatic upload, upload progress)
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
Pytorch Profiler+ Tensorboard + VS Code
Node red series (28): communication with Siemens PLC based on OPC UA node
Machine learning notes
学校实训要做一个注册页面,要打开数据库把注册页面输入的内容存进数据库但是
Refers to the difference between IP and *ip at output
Huawei cloud native - data development and datafactory
(04). Net Maui actual MVVM
UML diagrams and list collections
Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
lego_ Reading and summary of loam code
找到接口在表单里加参数
SQL追加字段
Thinkphp5 implements import function
节点CODE相同会导致数据重复
487-3279(POJ1002)