Does exists a yield_self function in javascript?

Viewed 195

Just out of curiosity as a Rubyist I wondered if JavaScript had something like the yield_self method of ruby.

"value".yield_self { |v| v[0] + v[4]}
=> "ve"

Which is a chainable method that uses the "object" you've called it on as value (super rough description) More examples: https://zverok.github.io/blog/2018-01-24-yield_self.html

I know that we have similar behaviour in Promises but I can imagine using it without Promise

"value".yieldSelf(v => v[0] + v[4])
0 Answers
Related