File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -859,6 +859,34 @@ will throw an error. If `original` is a function but its last argument is not
859
859
an error-first callback, it will still be passed an error-first
860
860
callback as its last argument.
861
861
862
+ Using ` promisify() ` on class methods or other methods that use ` this ` may not
863
+ work as expected unless handled specially:
864
+
865
+ ``` js
866
+ const util = require (' util' );
867
+
868
+ class Foo {
869
+ constructor () {
870
+ this .a = 42 ;
871
+ }
872
+
873
+ bar (callback ) {
874
+ callback (null , this .a );
875
+ }
876
+ }
877
+
878
+ const foo = new Foo ();
879
+
880
+ const naiveBar = util .promisify (foo .bar );
881
+ // TypeError: Cannot read property 'a' of undefined
882
+ // naiveBar().then(a => console.log(a));
883
+
884
+ naiveBar .call (foo).then ((a ) => console .log (a)); // '42'
885
+
886
+ const bindBar = naiveBar .bind (foo);
887
+ bindBar ().then ((a ) => console .log (a)); // '42'
888
+ ```
889
+
862
890
### Custom promisified functions
863
891
864
892
Using the ` util.promisify.custom ` symbol one can override the return value of
You can’t perform that action at this time.
0 commit comments