@@ -29,7 +29,6 @@ new Parser(options);
29
29
* ` returnFatalError ` : * function* ; optional, defaults to the returnError function
30
30
* ` returnBuffers ` : * boolean* ; optional, defaults to false
31
31
* ` name ` : * javascript|hiredis* ; optional, defaults to hiredis and falls back to the js parser if not available
32
- * ` context ` : * A class instance that the return functions get bound to* ; optional
33
32
34
33
### Example
35
34
@@ -45,10 +44,15 @@ Library.prototype.returnFatalError = function (err) { ... }
45
44
var lib = new Library ();
46
45
47
46
var parser = new Parser ({
48
- returnReply: returnReply,
49
- returnError: returnError,
50
- returnFatalError: returnFatalError,
51
- context: lib
47
+ returnReply : function (reply ) {
48
+ lib .returnReply (reply);
49
+ },
50
+ returnError : function (err ) {
51
+ lib .returnError (err);
52
+ },
53
+ returnFatalError : function (err ) {
54
+ lib .returnFatalError (err);
55
+ }
52
56
}); // This returns either a hiredis or the js parser instance depending on what's available
53
57
54
58
Library .prototype .streamHandler = function () {
@@ -58,17 +62,20 @@ Library.prototype.streamHandler = function () {
58
62
});
59
63
};
60
64
```
61
- You do not have to use the context variable, but can also bind the function while passing them to the option object .
65
+ You do not have to use the returnFatalError function. Fatal errors will be returned in the normal error function in that case .
62
66
63
67
And if you want to return buffers instead of strings, you can do this by adding the returnBuffers option.
64
68
65
69
``` js
66
70
// Same functions as in the first example
67
71
68
72
var parser = new Parser ({
69
- returnReply: returnReply .bind (lib),
70
- returnError: returnError .bind (lib),
71
- returnFatalError: returnFatalError .bind (lib),
73
+ returnReply : function (reply ) {
74
+ lib .returnReply (reply);
75
+ },
76
+ returnError : function (err ) {
77
+ lib .returnError (err);
78
+ },
72
79
returnBuffers: true // All strings are returned as buffer e.g. <Buffer 48 65 6c 6c 6f>
73
80
});
74
81
0 commit comments