Home > Web Front-end > JS Tutorial > Introduction to the use of two common methods of function calling in js_javascript skills

Introduction to the use of two common methods of function calling in js_javascript skills

WBOY
Release: 2016-05-16 16:41:46
Original
1344 people have browsed it

A js function

function test(aa){
window.alert("你输入的是"+aa);
}
Copy after login

Method 1: Call

directly

test("dddd");

Method 2: Assign function to variable

var abc=test;

abc('China');//Use variables to call functions

Note:

When we write it in this form, var abc=test("dddd"); cannot call the function through the variable abc.

This way of writing will assign the return value to abc when test has a return value. When there is no return value, the value of abc is undefined.

Specially emphasize that js naturally supports variable parameters

//编写一个函数,可以接受任意多个数,并计算他们的和
//无法重载,abc2函数名不能重复
function abc2(n1){// 可以无视参数n1
//在js中有一个arguments,可以访问所有传入的值。
//window.alert(arguments.length);
//遍历所有的参数
for(var i=0;i<arguments.length;i++){
window.alert(arguments[i]);
}
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template