如何将值'undefined'传递给具有多个参数的函数? [英] How to pass the value 'undefined' to a function with multiple parameters?

查看:125
本文介绍了如何将值'undefined'传递给具有多个参数的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多参数函数中传递'undefined'的值,但不省略参数。

我的意思是没有省略参数。我的意思是我们不应该像这个例子一样忽略 parm2

  function myFunction(parm1,parm2){} 
myFunction(abc);

这确实会使 parm2 未定义,但但我不能这样做,因为我需要在省略参数后指定其他参数。



所以在这种情况下,我想使 parm1 undefined但是也想在这个之后有其他参数来保存一个值,这对于以前的方法来说是行不通的



<我已经尝试过:

  myFunction(,abc); //似乎不起作用

和:

  myFunction(undefined,abc); //既不工作也不工作


解决方案

使用命名属性,然后查找那些特定的属性值。这样你就不必依赖于参数的数量。


I want to pass the value of 'undefined' on a multiple parameter function but without omitting the parameter.

What do I mean with "without omitting the parameter". I mean that we should not just omit the parm2 like this example:

function myFunction (parm1, parm2) {}
myFunction("abc");

This will indeed make parm2 undefined, but however I am not allowed to do it this way because I will need to specify other parameters AFTER the omitted parameter.

So in the case I want to make parm1 undefined BUT also want to have other parameters after this one to hold a value won't work with the previous method.

I have tried with:

myFunction( ,"abc"); //don't seem to work

And:

myFunction(undefined,"abc"); //neither work

解决方案

A better approach might be passing Object with named attributes and then look for those specific attribute values. This way you don't have to be dependent on number of arguments.

这篇关于如何将值'undefined'传递给具有多个参数的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆