Add functions, functionsIn

This commit is contained in:
Angelos Chalaris
2018-01-11 21:18:58 +02:00
parent beda1ea589
commit ed2089a292
3 changed files with 40 additions and 0 deletions

18
snippets/functions.md Normal file
View File

@ -0,0 +1,18 @@
### 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.
```js
const functions = obj =>
Object.keys(obj).filter(key => typeof obj[key] === 'function');
```
```js
function Foo() {
this.a = () => 1;
this.b = () => 2;
}
functions(new Foo); // ['a', 'b']
```