Q:

Write a JavaScript program to get an array of function property names from own (and optionally inherited) enumerable properties of an object

0

 Write a JavaScript program to get an array of function property names from own (and optionally inherited) enumerable properties of an object

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const functions = (obj, inherited = false) =>
  (inherited
    ? [...Object.keys(obj), ...Object.keys(Object.getPrototypeOf(obj))]
    : Object.keys(obj)
  ).filter(key => typeof obj[key] === 'function');
function Foo() {
  this.a = () => 1;
  this.b = () => 2;
}
Foo.prototype.c = () => 3;
console.log(functions(new Foo()));
console.log(functions(new Foo(), true));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now