post 重复参数_参数名称重复

post 重复参数

Oftentimes we override or monkey patch functions and, in many cases, there are arguments we don't care too much about. A common practice for those arguments is using _ for argument names -- it's a generally accepted and known practice for "this isn't important". I started thinking about multiple useless arguments and if you could use the same name for the sake of minification -- you can.

通常,我们会覆盖或猴子补丁函数,并且在许多情况下,有些参数我们不太在意。 这些参数的常见做法是使用_作为参数名称-这是“这并不重要”的普遍接受的已知做法。 我开始考虑多个无用的参数,如果为了简化而可以使用相同的名称,则可以。

So what happens when you use the same argument name more than once? An error? Uses the first value? The last value? Let's have a look:

那么当您多次使用相同的参数名称时会发生什么呢? 一个错误? 使用第一个值? 最后的价值? 我们来看一下:

function myFunc(_, _, _) {
  console.log("_: ", _);
}

myFunc(1, 2, 3);

// >> 3

The duplicated argument is given the value of the last provided argument. If, however, "use strict" is used, an error will be thrown.

为重复的参数提供最后提供的参数的值。 但是,如果"use strict" ,将引发错误。

For some reason I expected an error when using an argument name more than once. On the other end, you can change argument values so I shouldn't be surprised. Anyway, happy coding!

由于某种原因,我多次使用参数名称时会出现错误。 另一方面,您可以更改参数值,这样我就不会感到惊讶。 无论如何,祝您编程愉快!

翻译自: https://davidwalsh.name/duplicated-argument-names

post 重复参数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值