1. Extension of string
Adds an Iterator to the string, which can be traversed by for...of
includes, startsWith and endsWith both return Boolean values and support the second parameter (the starting position of the search). endsWith targets the first n characters, and the other two are from the nth to the end
repeat returns a new string, and the parameter is the number of repetitions (the decimal will be rounded down, a negative number or Infnity will report an error, 0 to -1 is equivalent to 0, and the string will be converted to a number)
padStart and padEnd are completed at the head or tail. The first parameter is the minimum length of the string, and the second parameter is the string used for completion.
Template String `${...}`
2. Numeric expansion
Number.isFinite checks whether a value is finite, All non-numeric values return false
Number.isNaN checks whether a value is NaN, and only NaN returns true;
The traditional method isFinite isNaN will first call Number() to convert the non-numeric value Convert to a numerical valueNumber.parseInt(), Number.parseFloat() are the same as the traditional methods, the purpose is to reduce the global method and language modularization
Number.isInteger() determines whether it is an integer
Number.EPSILON is a very small constant. If the error of floating point calculation is less than this value, it is ok
The exact integer range of JS: -2^53~2^53 (excluding both ends),
Number.MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
Number.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;
Number.isSafeInteger() is used to determine whether an integer falls within this range;Math.trunc() removes the decimal part and returns an integer Part;
Math.sign() determines whether it is a negative integer or 0;
Math.cbrt() calculates the cube root of a number; there are also some logarithmic methods and trigonometric function methods;
Exponential operator 2 * * 3 === 8, which is different from the Math.pow implementation. For particularly large operations, the last digit of the operation result is different;
3. Array expansion
Array.from can convert array-like objects and traversable objects into arrays, and the spread operator can also convert certain objects into arrays;
can accept a second parameter, similar to the map method , returns the processed value to an array;Array.of converts a set of values into an array;
copyWithin copies the member at the specified location to other locations;
Array.prototype.copyWithin(target, start = 0, end = this.length)find finds the first qualified member, the parameter is one Callback function;
findIndex returns the position of the first array member that meets the conditions-
fill fills the array with the given value, and the second and third parameters can specify the start and end positions;
keys, values, entries
includes, indexOf is not semantic enough, and is used internally == judgment,
[NaN] .indexOf(NaN) // -1 , [NaN].includes(NaN) // true
Map's has is used to find key names, Set's has is used to find valuesThe empty position of the array has no value, 0 in [,,] // false, es6 will convert the empty position to undefined, and the empty position should be avoided
four . Function extension
allows setting default values for functions. If default values are set for non-tail parameters, in fact this parameter cannot be omitted;
After setting the default value , thelength
attribute of the function will return the number of parameters without a specified default value;
If the parameter with a default value set is not the tail parameter, then thelength
attribute will not be counted. Enter the following parameters;Once the default value of the parameter is set, when the function is declared and initialized, the parameters will form a separate scope (context). When the initialization is completed, this scope will disappear. This syntax behavior will not appear when the parameter default value is not set.
Rest parameter (... variable name)
-
Extension operator (...), convert an array to comma-separated parameter sequence.
/* 替代数组的apply方法 */// ES5的写法function f(x, y, z) { // ...}var args = [0, 1, 2]; f.apply(null, args);// ES6的写法function f(x, y, z) { // ...}var args = [0, 1, 2]; f(...args);/* --------------------------------- */// ES5的写法Math.max.apply(null, [14, 3, 77])// ES6的写法Math.max(...[14, 3, 77])// 等同于Math.max(14, 3, 77);/* --------------------------------- */// ES5的写法var arr1 = [0, 1, 2];var arr2 = [3, 4, 5]; Array.prototype.push.apply(arr1, arr2);// ES6的写法var arr1 = [0, 1, 2];var arr2 = [3, 4, 5]; arr1.push(...arr2);
-
Notes on using arrow functions:
(1) The
this
object in the function body is the definition The object in which it is located at the time of use, not the object in which it is used.(2) cannot be used as a constructor, that is to say, the
new
command cannot be used, otherwise an error will be thrown.(3) The
arguments
object cannot be used, as the object does not exist in the function body. If you want to use it, you can use the rest parameter instead.(4) The
yield
command cannot be used, so the arrow function cannot be used as a Generator function.
5. Object extension
Abbreviated representation of attributes
Attribute name expression, [variable name]
The
name
attribute of the method returns the function name (i.e. method name)-
Object.is is basically the same as ===. The difference is that
+0
is not equal to-0
, andNaN
is equal to itself
// es5实现Object.isObject.defineProperty(Object, 'is', { value: function(x, y) {if (x === y) { // 针对+0 不等于 -0的情况 return x !== 0 || 1 / x === 1 / y; }// 针对NaN的情况return x !== x && y !== y; }, configurable: true, enumerable: false, writable: true});
Object.assign(target, o1, o2) is used to merge objects. If there are properties with the same name, the previous ones will be overwritten later; the shallow copy executed
cannot be converted due to undefined and null into objects, so if they are used as parameters, an error will be reported;Object.getOwnPropertyDescriptor method can obtain the description object of the property.
Traversal of properties:
for...in, Object.keys, Object.getOwnPropertyNames(obj), Object.getOwnPropertySymbols(obj), Reflect.ownKeys(obj)__proto__ has the same function as Object.setPrototypeOf(), used to set the prototype object of an object, Object.getPrototypeOf()
Object. keys(), Object.values(), Object.entries()
Object.getOwnPropertyDescriptors returns the description object of all its own properties (non-inherited properties) of the specified object;
The above is the detailed content of Detailed explanation of extended examples of various data types in es6. For more information, please follow other related articles on the PHP Chinese website!

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

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

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

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

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

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

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

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
