请一些机构帮我回复功能 [英] Please some body help me with return type of function

查看:72
本文介绍了请一些机构帮我回复功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请一位有关返回功能的人帮助我



功能xyz()

{

document.getelementById(txtbox);

}





这个函数将返回什么? ?

解决方案

1)Javascript函数不必返回任何内容。 2)即使某些Javascript函数总是返回某些内容,也可能无法定义特定类型的返回值;通常,Javascript使用动态类型范例:

http:// en .wikipedia.org / wiki / JavaScript #Dynamic [ ^ ]。



这可能需要一些额外的解释:类型与值相关,而不是变量。即使是相同的函数,取决于传递的参数,也可能返回不同类型的不同的东西,根本不返回任何东西,这将导致未定义对象的赋值。例如,下面显示的函数将返回什么类型?尝试确定它:

  function  whoKnowsWhat(输入){
if (输入!= 3
return 输入;
}

someVariable = whoKnowsWhat( 3 ); // 将分配什么?
someVariable = whoKnowsWhat( some string); // 将成为字符串
someVariable = whoKnowsWhat( 12 ); // 将成为整数



In在这个例子中,函数将返回不同类型的对象并将它们分配给同一个变量。在第一种情况下,没有返回任何内容,因此这意味着保持变量未分配。



-SA


< blockquote>没什么。

在这里找出你自己的原因:学习JavaScript [ ^ ]


Hi please some one help me regarding return type of function

function xyz()
{
document.getelementById("txtbox");
}


what does this function will return ??

解决方案

1) Javascript function does not have to return anything. 2) Even if some Javascript function always returns something, the particular type of return may not be defined; generally, Javascript uses dynamic typing paradigm:
http://en.wikipedia.org/wiki/JavaScript#Dynamic[^].

This may need some additional explanation: "types are associated with values, not variables". Even the same very function, depending, say, on parameters passed, may return different things of different type of not return anything at all, which will cause assignment of undefined object. What "type", for example, will be returned by the function shown below? Try to determine it:

function whoKnowsWhat(input) {
   if (input != 3)
      return input;
}

someVariable = whoKnowsWhat(3); // what will be assigned?
someVariable = whoKnowsWhat("some string"); // will become a string
someVariable = whoKnowsWhat(12); // will become an integer


In this example, the function will return object of different types and assign them to the same variable. In first case, nothing is returned, so this means leaving the variable unassigned.

—SA


Nothing.
Find out the reason for yourself here: Learn JavaScript[^]


这篇关于请一些机构帮我回复功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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