-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathf-functor.js
More file actions
34 lines (26 loc) · 585 Bytes
/
Copy pathf-functor.js
File metadata and controls
34 lines (26 loc) · 585 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
function Functor() {}
Functor.prototype.method = function() {
console.log('Functor.prototype.method');
console.dir({
property: this.property,
method: this.method,
});
this(); // you can call this as a function
};
const factory = () => {
const functor = function() {
console.log('functor');
functor.property = 'value';
console.dir({
property: functor.property,
method: functor.method,
});
};
Object.setPrototypeOf(functor, Functor.prototype);
return functor;
};
// Usage
const fn = factory();
fn();
fn.method();