...

/

Property Access and Modification

Property Access and Modification

access, modify (update and delete) properties of Objects

We'll cover the following...

Reflect.has determines if a property exists for a given target object. The call enumerates all properties, not only own properties.

Press + to interact
let target = class Account {
constructor( name, email ) {
this.name = name;
this.email = email;
}
get contact() {
return `${this.name} <${this.email}>`;
}
};
let args = [
'Zsolt',
'info@zsoltnagy.eu'
];
let myAccount = Reflect.construct(
target,
args );
console.log(Reflect.has( myAccount, 'name' ));
console.log(Reflect.has( myAccount, 'contact' ));

Reflect.ownKeys returns all own properties of a target in an array.

Press + to interact
console.log(Reflect.ownKeys( myAccount ));

Reflect.get gets a property based on a key. As an optional parameter, the this context can be specified.

Press + to interact
console.log(Reflect.get( myAccount, 'name' ));
//> "Zsolt"
console.log(Reflect.get( myAccount, 'contact' ));
//> "Zsolt - 555-1269"

Getting the name property of myAccount is straightforward. In the second example, ...