8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c7c0091 commit 859b468Copy full SHA for 859b468
JavaScript/f-functor.js
@@ -0,0 +1,38 @@
1
+'use strict';
2
+
3
+const util = require('util');
4
5
+function Functor() {
6
+}
7
8
+Functor.prototype.method = function() {
9
+ console.log('Functor.prototype.method');
10
+ console.dir({
11
+ property: this.property,
12
+ exec: this.method
13
+ });
14
+ this(); // you can call this as a function
15
+};
16
17
+util.inherits(Functor, Function);
18
19
+const factory = () => {
20
21
+ const functor = function() {
22
+ console.log('functor');
23
+ functor.property = 'value';
24
25
+ property: functor.property,
26
+ method: functor.method
27
28
+ };
29
30
+ Object.setPrototypeOf(functor, Functor.prototype);
31
+ return functor;
32
33
34
+// Usage
35
36
+const fn = factory();
37
+fn();
38
+fn.method();
0 commit comments