javascript - Array splicing with coffeescript, what is _ref for? - Stack Overflow

In the CoffeeScript docs for array splicing, what is the purpose of the trailing , _ref?CoffeeScript:nu

In the CoffeeScript docs for array splicing, what is the purpose of the trailing , _ref?

CoffeeScript:

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

Compiles to:

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;

In the CoffeeScript docs for array splicing, what is the purpose of the trailing , _ref?

CoffeeScript:

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

Compiles to:

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;
Share Improve this question asked Jul 28, 2012 at 11:06 AJPAJP 28.7k26 gold badges94 silver badges144 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

That's because CoffeeScript's slicing operation wants to return the slice it has just assigned, but splice() returns the removed elements instead.

So, in order to achieve this, it piles the construct into a code fragment that first assigns the slice to a local _ref variable, then uses the ma operator to return that variable after calling splice().

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745112417a4611924.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信