调用函数语法 [英] Call a function syntax

查看:107
本文介绍了调用函数语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解一段代码。在javascrpit文件中,

有一个函数:


函数ItemStyle(){

var names = [''len '',''spacing'',''popInd'',''popPos'',''pad'',''outCol'',''overCol'',''outClass'',''overClass'' ,''outBorder'',''overB order'','outAlpha'',''overAlpha'',''normCursor'',''nullCu rsor''];

addProps(这个,参数,名字,真);

};


在html文件中,它将函数调用为:


var hBar = new ItemStyle(40,10,'''',0,0,''10#336699'',''10#6699CC'',

''highText '','''highText'','''','''',

null,null,''hand'',''default'');


当函数

没有参数时,如何将15个参数传递给函数?

解决方案

>当函数

没有参数时,如何将15个参数传递给函数?




你不必正式如果你不想,声明JavaScript

函数的参数。它们通过''参数''

数组传递。


chirs说:


我想了解一段代码。在javascrpit文件中,
有一个函数:

函数ItemStyle(){
var
names = [''len'',''spacing'' ,''popInd'',''popPos'',''pad'',''outCol'',''overCol'',''outClass'',''overClass'',''outBorder'',' 'overB order'','outAlpha'',''overAlpha'',''normCursor'',''nullCu rsor''];
addProps(this,arguments,names,true);
};

在html文件中,它将函数调用为:

var hBar = new ItemStyle(40,10,'''',0,0,' '10#336699'',''10#6699CC'',
''highText'',''highText'','''','''',
null,null,' 'hand'',''default'');

当函数
没有参数时,如何将15个参数传递给函数?




参数函数的属性(在函数中看作局部变量

)是传递给它的参数数组。


Graham J写道:

当函数
没有参数时,如何将15个参数传递给函数?



如果你不想,你不必正式宣布JavaScript
函数的论点。它们在''arguments''
数组中传递。




尽管它在核心参考中已经描述过,你可以

访问其属性,如数组的元素(使用索引

运算符),我不会称之为数组,因为它缺少功能

数组原型,如join(...)方法,并将其称为

a集合。

PointedEars


I am trying to understand a piece of code. In a javascrpit file,
there is a function:

function ItemStyle(){
var names=[''len'',''spacing'',''popInd'',''popPos'',''pad'',''outCol'','' overCol'',''outClass'',''overClass'',''outBorder'',''overB order'',''outAlpha'',''overAlpha'',''normCursor'',''nullCu rsor''];
addProps(this,arguments,names,true);
};

In the html file, it calls the function as:

var hBar = new ItemStyle(40, 10, '''', 0, 0, ''10#336699'', ''10#6699CC'',
''highText'', ''highText'', '''', '''',
null, null, ''hand'', ''default'');

How can it pass the 15 arguments to the function when the function
does not have parameters?

解决方案

> How can it pass the 15 arguments to the function when the function

does not have parameters?



You don''t have to formally declare the arguments of JavaScript
functions if you don''t want to. They are passed in the ''arguments''
array.


chirs said:


I am trying to understand a piece of code. In a javascrpit file,
there is a function:

function ItemStyle(){
var
names=[''len'',''spacing'',''popInd'',''popPos'',''pad'',''outCol'','' overCol'',''outClass'',''overClass'',''outBorder'',''overB order'',''outAlpha'',''overAlpha'',''normCursor'',''nullCu rsor''];
addProps(this,arguments,names,true);
};

In the html file, it calls the function as:

var hBar = new ItemStyle(40, 10, '''', 0, 0, ''10#336699'', ''10#6699CC'',
''highText'', ''highText'', '''', '''',
null, null, ''hand'', ''default'');

How can it pass the 15 arguments to the function when the function
does not have parameters?



The "arguments" attribute of the function (seen as a local variable
within the function) is the array of arguments passed to it.


Graham J wrote:

How can it pass the 15 arguments to the function when the function
does not have parameters?



You don''t have to formally declare the arguments of JavaScript
functions if you don''t want to. They are passed in the ''arguments''
array.



Although it is described in the Core Reference as such and you can
access its properties like the elements of an array (using the index
operator), I would not call it an array, since it is lacking features
of the Array prototype, like the join(...) method, and would call it
a collection instead.
PointedEars


这篇关于调用函数语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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