-3

I've seen Reflect function few times while researching through the nodejs source code in events.js module. And can't find definition of it.

Can anybody explain me what this function does?

brz
  • 115
  • 1
  • 7
  • 4
    How hard did you look? Literally the first result for "javascript reflect" is [the mdn docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect). – James Thorpe Jan 19 '18 at 13:07
  • And in future, if you still need to post a question after thoroughly searching (see above) please quote the code you're asknig about. There are lots of things with similar names. – T.J. Crowder Jan 19 '18 at 13:08
  • Does this answer your question? [What is javascript Reflect.construct newTarget doing](https://stackoverflow.com/questions/50346328/what-is-javascript-reflect-construct-newtarget-doing) – user1742529 Apr 14 '21 at 05:47

1 Answers1

2

Reflect is a new ES6 built-in object.

Reflect.apply(...) will execute a function with a list of passed arguments. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply

Code sample

function sum(a, b) {
  return a + b
}

const result = Reflect.apply(sum, undefined, [1, 2])
console.log(result)

// Same to
const result2 = sum.apply(undefined, [1, 2])
console.log(result2)
Vlad Miller
  • 2,255
  • 1
  • 20
  • 38
  • 1
    it seems i need a break and relax. i thought it's nodejs function like process.binding. thank you – brz Jan 19 '18 at 13:23