Loading lesson path
Concept visual
Start at both ends
Formula
Reflect is a object with methods for low - level operations on JavaScript objects.Reflect object you can get, set, delete, and check object properties in a consistent way.
ES6 (2015).
Reflect is a toolbox for working with objects in a safe and consistent way.
Before Reflect, object operations were scattered:
Object.defineProperty
[[
]] and [[
]]
Reflect brings all object operations into clean methods
Formula
Reflect methods are more predictable than operators (in/delete)Reflect methods provides standard return values instead of errors
Formula
Reflect methods are cleaner and safer for meta - programmingReflect methods are tailored for the Proxy object
Reflect.has(), you get the in operator as a function.
Reflect.delete(), you get the delete operator as a function.
Reflect is safe and flexible, especially when used inside a Proxy. Reflect.has()
Reflect.has() method checks if an object has a specific property.
Reflect.has() method is similar to the in operator.
// Create an Object const person = {name: "John", lastname: "Doe"};
let answer = Reflect.has(person, "name");Same as using the in operator:
let answer = "name" in person;Reflect.has(obj, prop)
Formula
Properties obj - the target object prop - the property to check
Returns true - if true false if falseTypeError thrown if obj is not an object Reflect.deleteProperty()
Reflect.deleteProperty() method deletes a property from an object.
Reflect.deleteProperty() method is similar to the delete operator.
// Create an Object const person = {name: "John", lastname: "Doe"};
Reflect.deleteProperty(person, "name");Same as using the delete operator:
delete person.name;