Files
30-seconds-of-code/snippets/functions.md
30secondsofcode 0fc59a817c Travis build: 1196
2018-01-11 19:20:57 +00:00

432 B

functions

Returns an array of function property names from own enumerable properties of object.

Use Object.keys(obj) to iterate over the object's own properties, Array.filter() to keep only those that are functions.

const functions = obj => Object.keys(obj).filter(key => typeof obj[key] === 'function');
function Foo() {
  this.a = () => 1;
  this.b = () => 2;
}
functions(new Foo()); // ['a', 'b']