What is the equivalent of Java double colon operator in typescript(if there's any):
stream.forEach( System.out::println(s));
EDIT: I know it's doable with certain functions like:
stream.forEach(console.log);
stream.filter(Boolean);
But when I use other functions e.g. BehaviorSubject "next" my code breaks. I don't know what qualifies those other two to be called by reference. I'd like to have something like:
stream.pipe(someSubject.next);
Instead of:
stream.pipe(value => someSubject.next(value));
Double colon ( :: ) is used as a seperator for nested JSON arrays.
The Bind Operator :: # The Bind operator consists of an introduction of a new operator :: (double colon), which acts as syntax sugar for the previous two use cases.
The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions.
:: is a new operator included in Java 8 that is used to refer to a method of an existing class. You can refer to static methods and non-static methods of a class. For referring to static methods, the syntax is: ClassName :: methodName.
Okay, so I did a bit of searching and there is a double colon operator in JScript, which was Microsoft's implementation of JavaScript:
a double colon is used as separator between the script ID and the event name
My guess is that's not part (or no longer part) of Internet explorer's ECMAScript implementation but it belongs (or used to belong) to Microsoft Office's implementation
What does ‘::’ (double colon) do in javascript for events?
Which was a really cool find, but I've never seen a double colon operator being used in TS or ECMAScript.
You can use lambda expressions
[].forEach((item: any) => console.log(item))
but I'm pretty sure JS or TS doesn't have a wrapper for a lambda expression like Java does.
EDIT: I also found this What does ‘::’ (double colon) do in JavaScript? after a little more searching and it is also a valid ES7 operator as syntactic sugar for bind: http://blog.jeremyfairbank.com/javascript/javascript-es7-function-bind-syntax/
Although it doesn't behave the same way as Java's :: operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With