search
HomeWeb Front-endJS TutorialES6 object assignment and Symbol
ES6 object assignment and SymbolMar 10, 2018 pm 03:00 PM
objectAssignment

This time I will bring you the assignment and Symbol of ES6 objects. What are the precautions for using the assignment and Symbol of ES6 objects? The following is a practical case, let's take a look.

Object assignment merge:

//es6语法允许变量直接为对象的赋值,快捷方便;
let liu="呵呵哒";
let long="赖皮哒";
let a={liu,long};
console.log(a) ;
//es6语法允许为对象构建key值;
let key='skill';
var obj={ [key]:'web'}
console.log(obj.skill);
//es6语法允许直接合并对象;
let s={liuliu:"wowoda",age:20};
let ss={long:"赖皮"};
let sss=Object.assign(s,ss);
console.log(sss);
//object.is()方法判断是否相等;

The two equal signs will automatically perform

type conversion during comparison, while the three equal signs will not. If the type Different, it will return false directly,

and Object.is() is based on the third equal sign, and specially handles NaN, -0, +0, ensuring that -0 and +0 are no longer Same,

But it should be noted that Object.is(NaN, NaN) will return true

Symbol: As a new

data type was born in es6 : Symbol literally means symbolic, representing the uniqueness of something;

 let myId=Symbol();
 let myname=Symbol();          
 console.log (myname)       ===>Symbol()
 typeof myname             ===>symbol
 console.log(myId===myname)        ===>false

You can think of Symbol as a basic data type similar to

String; it cannot be operated with other types ;It cannot be converted implicitly;

A Symbol() can be considered as a new function created in memory (so it is not wrong to say that parentheses are the symbol of a function);

The Symbol function can also pass in parameters; the parameters are only used as a description of this Symbo;

 let myId=Symbol("id");
 let myname=Symbol("名字");

Even if the parameters of two Symbols are the same, they are not equal; because a new memory space is created;

The biggest use of Symbol is as an object’s

attribute to ensure uniqueness;

 let system=Symbol();
 let foo={};
 foo[system]="windows";       //还可以保证key值为symbol类型的不被 for in遍历出来;
                                            //同样还证明了一点:对象的访问方式,要么以 . ;要么以["这里必须是字符串"];js的底层全部是字符串这种实现;
 console.log(foo);

Symbol can also share a sign;

 let sy=Symbol.for("aaa");

Symbol.for( " ") does not create a new memory every time; there is only one at most; if the aaa flag does not exist in the page, create one, and if there is, directly reference the previous address;

For example:

 let cccc=Symbol.for("aaa");

Then: console.log(sy===cccc); //true; It is also easy to understand; in the end, the uniqueness of a Symbol type with aaa description is guaranteed;

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Related reading:

Detailed explanation of destructuring assignment in ES6

Detailed explanation of scope and declaration of variables in ES6

The above is the detailed content of ES6 object assignment and Symbol. 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
如何为VMware虚拟机启用复制和粘贴如何为VMware虚拟机启用复制和粘贴Feb 21, 2024 am 10:09 AM

您可以轻松地在VMware虚拟机(VM)和物理系统之间复制和粘贴文本和文件。这种功能让您可以方便地在虚拟机和主机系统之间传输图像、格式化和非格式化文本,甚至电子邮件附件。本文将向您展示如何启用这一功能,并演示复制数据、文件和文件夹的方法。如何在VMware中启用复制/粘贴VMware提供了三种不同的方式将数据、文件或文件夹从虚拟机复制到物理计算机,反之亦然,如下所述:复制和粘贴要素拖放功能文件夹共享1]使用VMware工具启用复制粘贴如果您的VMWare安装和来宾操作系统满足要求,则可以使用键盘

如何在Word中复制页面如何在Word中复制页面Feb 20, 2024 am 10:09 AM

是否要复制MicrosoftWord中的页面,并保持格式不变?这是一个聪明的想法,因为当您想要创建特定文档布局或格式的多个副本时,在Word中复制页面可能是一种有用的节省时间的技术。本指南将逐步引导您在Word中复制页面的过程,无论是创建模板还是复制文档中的特定页面。这些简单的说明旨在帮助您轻松地重新制作页面,省去从头开始的麻烦。为什么要在MicrosoftWord中复制页面?在Word中复制页面非常有益的原因有以下几点:当您有一个具有特定布局或格式的文档要复制时。与从头开始重新创建整个页面不同

源码探秘:Python 中对象是如何被调用的?源码探秘:Python 中对象是如何被调用的?May 11, 2023 am 11:46 AM

楔子我们知道对象被创建,主要有两种方式,一种是通过Python/CAPI,另一种是通过调用类型对象。对于内置类型的实例对象而言,这两种方式都是支持的,比如列表,我们即可以通过[]创建,也可以通过list(),前者是Python/CAPI,后者是调用类型对象。但对于自定义类的实例对象而言,我们只能通过调用类型对象的方式来创建。而一个对象如果可以被调用,那么这个对象就是callable,否则就不是callable。而决定一个对象是不是callable,就取决于其对应的类型对象中是否定义了某个方法。如

使用Python的__contains__()函数定义对象的包含操作使用Python的__contains__()函数定义对象的包含操作Aug 22, 2023 pm 04:23 PM

使用Python的__contains__()函数定义对象的包含操作Python是一种简洁而强大的编程语言,提供了许多强大的功能来处理各种类型的数据。其中之一是通过定义__contains__()函数来实现对象的包含操作。本文将介绍如何使用__contains__()函数来定义对象的包含操作,并且给出一些示例代码。__contains__()函数是Pytho

在终端中禁用或启用自动复制所选内容以进行复制在终端中禁用或启用自动复制所选内容以进行复制Mar 24, 2024 am 09:46 AM

本文将向您介绍如何在Windows终端中启用或禁用自动将选择内容复制到剪贴板的功能。Windows终端是微软专为Windows11/10开发的多标签终端模拟器,取代了传统的命令提示符。它支持运行命令提示符、PowerShell、WSL、Azure等应用程序。通常在终端工作时,用户需要复制命令和输出,然而终端默认情况下不支持复制选择操作。请继续阅读本文,了解如何解决这个问题。如何在终端中启用或禁用自动复制所选内容到缓存?以下是您如何启用或禁用自动复制选择到终端剪贴板:打开终端应用程序,然后点击上面

使用Python的__le__()函数定义两个对象的小于等于比较使用Python的__le__()函数定义两个对象的小于等于比较Aug 21, 2023 pm 09:29 PM

标题:使用Python的__le__()函数定义两个对象的小于等于比较在Python中,我们可以通过使用特殊方法来定义对象之间的比较操作。其中之一就是__le__()函数,它用于定义小于等于比较。__le__()函数是Python中的一个魔法方法,并且是一种用于实现“小于等于”操作的特殊函数。当我们使用小于等于运算符(<=)比较两个对象时,Python

解锁 macOS 剪贴板历史记录,高效复制、粘贴技巧解锁 macOS 剪贴板历史记录,高效复制、粘贴技巧Feb 19, 2024 pm 01:18 PM

在Mac上,经常需要在不同文档之间复制和粘贴内容是常见的。macOS的剪贴板只保留最后一个复制项,这限制了我们的工作效率。幸运的是,有一些第三方应用程序可以帮助我们轻松查看和管理剪贴板的历史记录。如何在「访达」中查看剪贴板内容「访达」中内置了一个剪贴板查看器,让你可以随时查看当前剪贴板中的内容,以免错误粘贴。操作非常简单:打开「访达」,点击「编辑」菜单,然后选择「显示剪贴板」。在「访达」中查看剪贴板内容这个功能虽小,却有几点需要注意:「访达」中的剪贴板查看器只能显示内容,无法编辑。如果你复制的是

详解Javascript对象的5种循环遍历方法详解Javascript对象的5种循环遍历方法Aug 04, 2022 pm 05:28 PM

Javascript对象如何循环遍历?下面本篇文章给大家详细介绍5种JS对象遍历方法,并浅显对比一下这5种方法,希望对大家有所帮助!

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

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.