Skip to content

Commit

Permalink
add: Reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
thutasann committed Dec 3, 2024
1 parent feb26f0 commit 9894f2e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions standalone-apis/pure-nodejs-concepts/concepts/proxy/reflect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ----- Reflect.set/Reflect.get
const obj = { name: 'John', age: 30 };
console.log(Reflect.get(obj, 'name'));

Reflect.set(obj, 'age', 35);
console.log('obj age', obj.age);

// ------ Relect.has
console.log('hasName -> ', Reflect.has(obj, 'name'));

// ------ Relect.apply
function greet(message) {
return `${message}, ${this.name}`;
}
const person = { name: 'Alice' };

const apply_result = Reflect.apply(greet, person, ['Hello']);
console.log('apply_result', apply_result);

// ------ Relect.construct
class Person {
constructor(name) {
this.name = name;
}
}

const john = Reflect.construct(Person, ['John']);
console.log(john.name);

0 comments on commit 9894f2e

Please sign in to comment.