Splitting an array using coffeescript, what is _ref?

In CoffeeScript docs for splicing arrays , what is the purpose of the final , _ref ?

CoffeeScript:

 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] numbers[3..6] = [-3, -4, -5, -6] 

Compiles:

 var numbers, _ref; numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; [].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _ref; 
+6
source share
1 answer

This is because the CoffeeScript cut operation wants to return the newly selected slice, but splice () returns the deleted items.

So, to achieve this, he compiles the construct into a piece of code that first assigns a slice to the local variable _ref , and then uses a comma to return this variable after calling splice() .

+7
source

Source: https://habr.com/ru/post/921558/


All Articles