search
HomeWeb Front-endJS TutorialIntroduction to the use of two common methods of function calling in js_javascript skills

A js function

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

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]);
}
}
Statement
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
C++ 中如何在不同模块中调用函数?C++ 中如何在不同模块中调用函数?Apr 12, 2024 pm 03:54 PM

在C++中跨模块调用函数:声明函数:在目标模块的头文件中声明要调用的函数。实现函数:在源文件中实现函数。链接模块:使用链接器将包含函数声明和实现的模块链接在一起。调用函数:在需要调用的模块中包含目标模块的头文件,然后调用函数。

探索 PHP 函数调用的各种方式探索 PHP 函数调用的各种方式Apr 16, 2024 pm 02:03 PM

PHP函数调用共有五种方式:直接调用、通过变量调用、匿名函数、函数指针和反射。通过选择最适合情况的方法,可以优化性能和提高代码简洁性。

C++ 函数调用机制详解C++ 函数调用机制详解Apr 11, 2024 pm 02:12 PM

C++中的函数调用机制涉及将参数传递给函数并执行其代码,返回结果(如果存在)。参数传递有两种方式:值传递(修改在函数内部进行)和引用传递(修改反映在调用者中)。在值传递中,函数内的值修改不影响原始值(如printValue),而引用传递中的修改会影响原始值(如printReference)。

C++ 函数调用单元测试:参数传递和返回值的正确性验证C++ 函数调用单元测试:参数传递和返回值的正确性验证May 01, 2024 pm 02:54 PM

单元测试中验证C++函数调用时,需验证以下两点:参数传递:使用断言检查实际参数是否与预期值匹配。返回值:使用断言检查实际返回值是否等于预期值。

C++ 函数调用重载机制:参数传递和返回值的多义性处理C++ 函数调用重载机制:参数传递和返回值的多义性处理May 01, 2024 am 09:24 AM

C++函数重载允许同一函数名定义多个变体,根据不同形参列表区分。参数传递有值传递和引用传递两种,值传递将值复制到局部变量,引用传递将引用传递给函数,修改引用会影响外部变量。函数可返回不同类型的值,包括基本数据类型、引用和对象。

C++编译错误:函数调用与函数声明不符,应该怎样解决?C++编译错误:函数调用与函数声明不符,应该怎样解决?Aug 22, 2023 pm 12:39 PM

C++编译错误:函数调用与函数声明不符,应该怎样解决?在开发C++程序时,难免会遇到一些编译错误,其中之一常见的错误是函数调用与函数声明不符的错误。这种错误广泛存在于C++程序员中,由于不注意函数声明的正确性,导致编译问题,最终浪费时间和精力修复问题,影响开发效率。避免这种错误的方法需要遵循一些规范和标准实践,下面让我们来了解一下。什么是函数调用与函数声明不

解决C++代码中出现的“error: no matching function for call to 'function'”问题解决C++代码中出现的“error: no matching function for call to 'function'”问题Aug 26, 2023 pm 05:37 PM

解决C++代码中出现的“error:nomatchingfunctionforcallto'function'”问题在使用C++进行编程的过程中,经常会遇到“error:nomatchingfunctionforcallto'function'”的错误信息。这种错误通常表示在调用函数时,编译器无法找到与函数调用匹配的函数定义。这种

解决UniApp报错:'xxx'函数调用失败的问题解决UniApp报错:'xxx'函数调用失败的问题Nov 25, 2023 am 09:53 AM

解决UniApp报错:'xxx'函数调用失败的问题在开发使用UniApp进行跨平台应用开发时,我们常常会遇到函数调用失败的情况。这些错误可能是由于代码逻辑错误、插件引用错误、API参数错误等引起的。本文将介绍一些常见的解决方法,以帮助开发者快速解决UniApp报错:'xxx'函数调用失败的问题。一、检查代码逻辑首先,我们需要检查代码逻辑。有时候,函数调用失败

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment