search
HomeWeb Front-endJS TutorialExample tutorial of function extension in ES6
Example tutorial of function extension in ES6Jun 26, 2017 am 09:56 AM
functionstudyExpandseries

Some new features have also been added in the direction of function expansion. I feel that these features are also very important.

1. Parameter default values ​​(note: the default value cannot be followed by Add parameters without default values)

{  function test(x, y = 'world'){
    console.log('默认值',x,y);
  }
  test('hello');//hello world
  test('hello','kill');//hello kill
}
{
  let x='test';  function test2(x,y=x){
    console.log('作用域',x,y);
  }
  test2('kill');//kill kill  这里涉及到作用域的问题   函数里面具有单独的作用域  只有没有x的时候 才会继承let所声明的x
}

 2. Rest parameters (...) Convert a series of discrete values ​​into Array Similarly, rest cannot be followed by any parameters

{  function test3(...arg){for(let v of arg){
      console.log('rest',v);
    }
  }
  test3(1,2,3,4,'a');
}

 3. The spread operator (...) converts an array into a series of discrete values  

{
  console.log(...[1,2,4]);
  console.log('a',...[1,2,4]);
}

 4. Arrow function (very important, otherwise some new codes cannot be understood!!!) For example, a=> ;a*2 a is the parameter a*2 is the return value => as a symbol of the function When no parameters are passed, () can be used to represent

{
  let arrow = v => v*2;
  let arrow2 = () => 5;
  console.log('arrow',arrow(3));//6
  console.log(arrow2());//5

}

 5. Tail call If a function nests another function, you can consider tail call

{  function tail(x){
    console.log('tail',x);
  }  function fx(x){return tail(x)
  }
  fx(123)// tail 123
}

The above is the detailed content of Example tutorial of function extension in ES6. For more information, please follow other related articles on the PHP Chinese website!

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
php如何使用PHP的SNMP扩展?php如何使用PHP的SNMP扩展?Jun 02, 2023 am 10:22 AM

PHP的SNMP扩展是一种使PHP能够通过SNMP协议与网络设备进行通信的扩展程序。使用该扩展可以方便地获取和修改网络设备的配置信息,例如路由器、交换机等设备的CPU、内存、网络接口等信息,也可以进行诸如开关设备端口等控制操作。本文将介绍SNMP协议的基础知识、PHP的SNMP扩展的安装方法以及如何在PHP中使用SNMP扩展进行网络设备的监控和控制。一、SN

如何使用极光推送扩展,在PHP应用中实现批量消息推送功能如何使用极光推送扩展,在PHP应用中实现批量消息推送功能Jul 25, 2023 pm 08:07 PM

如何使用极光推送扩展,在PHP应用中实现批量消息推送功能在移动应用的开发中,消息推送是一项非常重要的功能。极光推送是一种常用的消息推送服务,提供了丰富的功能和接口。本文将介绍如何使用极光推送扩展在PHP应用中实现批量消息推送功能。第一步:注册极光推送账号并获取API密钥首先,我们需要在极光推送官网(https://www.jiguang.cn/push)注册

php如何使用PHP的ZipArchive扩展?php如何使用PHP的ZipArchive扩展?Jun 02, 2023 am 08:13 AM

PHP是一种流行的服务器端语言,可以用来开发Web应用程序和处理文件。PHP的ZipArchive扩展是一个强大的工具,可以在PHP中操作zip文件。在这篇文章中,我们将介绍如何使用PHP的ZipArchive扩展来创建、读取和修改zip文件。一、安装ZipArchive扩展在使用ZipArchive扩展之前,需要确保已经安装了这个扩展。安装方法如下:1.安

php如何使用PHP的POSIX扩展?php如何使用PHP的POSIX扩展?Jun 03, 2023 am 08:01 AM

PHP的POSIX扩展是一组允许PHP与POSIX兼容操作系统进行交互的函数和常量。POSIX(PortableOperatingSystemInterface)是一组操作系统接口标准,旨在允许软件开发人员编写可在各种UNIX或UNIX类操作系统上运行的应用程序。本文将介绍如何使用PHP的POSIX扩展,包括安装和使用。一、安装PHP的POSIX扩展在

php如何使用PHP的Phar扩展?php如何使用PHP的Phar扩展?May 31, 2023 pm 11:31 PM

随着PHP的发展和应用场景的不断扩大,Phar扩展已经成为PHP编程中的重要一环。Phar是PHPArchive的缩写,它可以将多个PHP文件和资源打包成单个文件,方便进行分发和管理。本文将介绍如何使用PHP的Phar扩展来进行打包和管理。安装Phar扩展首先,我们需要检查PHP是否已经安装Phar扩展。在Linux下,通过终端输入以下命令:php-m

Vue如何实现组件的复用和扩展?Vue如何实现组件的复用和扩展?Jun 27, 2023 am 10:22 AM

随着前端技术的不断发展,Vue已经成为了前端开发中的热门框架之一。在Vue中,组件是其中的核心概念之一,它可以将页面分解为更小,更易管理的部分,从而提高开发效率和代码复用性。本文将重点介绍Vue如何实现组件的复用和扩展。一、Vue组件复用mixinsmixins是Vue中的一种共享组件选项的方式。Mixins允许将多个组件的组件选项合并成一个对象,从而最大

PHP和WebDriver扩展:如何模拟用户点击和输入操作PHP和WebDriver扩展:如何模拟用户点击和输入操作Jul 07, 2023 pm 05:10 PM

PHP和WebDriver扩展:如何模拟用户点击和输入操作近年来,随着Web应用程序的快速发展,自动化测试变得越来越重要。在自动化测试中,模拟用户操作是一个关键的环节,它可以使我们更准确地测试和验证我们的应用程序。在PHP开发中,我们通常使用SeleniumWebDriver来实现自动化测试。SeleniumWebDriver是一种强大的工具,它可以模拟

教程:使用百度云推送(Baidu Push)扩展在PHP应用中实现消息推送功能教程:使用百度云推送(Baidu Push)扩展在PHP应用中实现消息推送功能Jul 26, 2023 am 09:25 AM

教程:使用百度云推送(BaiduPush)扩展在PHP应用中实现消息推送功能引言:随着移动应用的迅猛发展,消息推送功能在应用程序中变得越来越重要。为了实现即时通知和消息推送功能,百度提供了一种强大的云推送服务,即百度云推送(BaiduPush)。在本教程中,我们将学习如何使用百度云推送扩展(PHPSDK)在PHP应用中实现消息推送功能。我们将使用百度云

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor