-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream Transform with Arrow Functions #2740
Comments
An issue I hadn't considered: |
Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions Arrow Functions are not a replacement for regular functions. This is expected behaviour of the language feature, in this context it will bind to the wrong scope. You can't propagate |
@Fishrock123 I understand that it's expected behaviour, I explained that the issue is a result of the expected behaviour in the first line of my issue. My point was that now that ES6 usage is going to increase by a lot, we should perhaps consider finding a way to make this part of the API easier with both styles of functions without breaking existing codebases? |
Why would we want to? Arrow Functions are not a replacement for regular Functions.. |
A documentation PR indicating that arrow functions should not be used in this type of situation might be in order. Personally, I'd wait to see if people actually run into this problem frequently or not. But if someone felt strongly and wanted to be proactive about it, that's totally cool too. |
Because
this
in arrow functions is lexically bound, they cannot be used in providing a transform function to a stream.Transform object, in whichthis.push
is used to return data. See the following example:The callback function already accepts the output of the transform as its second argument. The following works:
In light of the fact that moving forward we're going to see a lot more people using the Arrow Function syntax, perhaps we should consider deprecating
this.push(data)
, or at least changing the docs so that thecallback(null,data);
pattern is recommended moving forward?I'd be very happy to submit a PR to the docs if there's any consensus on the right solution for this.
The text was updated successfully, but these errors were encountered: