龙空技术网

话说前端30-JavaScript的对象和闭包

LearningYard学苑 195

前言:

现时朋友们对“js对象foreach”大约比较关注,姐妹们都想要知道一些“js对象foreach”的相关内容。那么小编也在网摘上搜集了一些对于“js对象foreach””的相关内容,希望兄弟们能喜欢,朋友们一起来学习一下吧!

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。

今天小编为大家带来话说前端30-JavaScript的对象和闭包,欢迎您的访问。

Share interests, spread happiness, increase knowledge, and leave a good legacy!

Dear you, this is The LearningYard Academy.

Today Xiaobian brings you Knowledge set| Delayed Supply Chain Lexsim Modeling and Simulation, welcome to your visit.

什么是对象?在现实生活中,万物都可以是对象;对象是可以看的见摸得着的实物,比如:一辆车、一本书、一个人等等这些都是对象。再具体来把人打比方:人这个对象,具有名字,性别,年龄这些属性,也有唱歌这些方法。每个人都有这些属性和方法,但是每个人的具体名字叫什么,年龄或者性别可能都不一样。

What is an object? In real life, everything can be an object; Objects are tangible things that can be seen, such as a car, a book, a person and so on. Let's take people as an example: people have the attributes of name, gender and age, and they also have the methods of singing. Everyone has these attributes and methods, but everyone's specific name, age or gender may be different.

为什么需要对象?对象主要是为了更好的存储一组数据,对象中为每项数据设置了属性名称 可以访问数据更加语义化 数据结构清晰 表意明显。方便开发者的使用JS中的对象表达结构更清晰,更强大。

Why do you need objects? Objects are mainly used to better store a set of data, and attribute names are set for each item of data in the objects, so that the data can be accessed more semantically, and the data structure is clear and obvious. It is convenient for developers to use JS to express objects more clearly and powerfully.

在 JavaScript 中,对象是一组无序的相关属性和方法的集合,所有的事物都是对象,例如字符串、数值、数组、函数等。对象是由属性和方法组成的。属性:事物的特征,在对象中用属性来表示(一般都是名词)。方法:实物的行为,在对象中用方法来白哦是(一般都是动词)。

In JavaScript, an object is an unordered set of related attributes and methods. Everything is an object, such as strings, values, arrays, functions, etc. Objects are made up of properties and methods. Attribute: The characteristic of a thing, which is represented by an attribute in an object (usually a noun). Method: The act of a kind, which is white in the object with a method (usually a verb).

创建对象有两种方式

1.字面量创建对象

使用‘{ }’里面包含了对象的属性和方法,{ }里面采用键值对的形式表示。

键:相当于属性名

值:相当于属性值,属性值可以是任意数据类型的值。也可以是方法。

键与值之间用‘:’连接,每个键值对结束用‘,’分割

获取对象值的方法: 变量.属性。

There are two ways to create objects.

1. Literally create objects

The use of' {0}' contains the properties and methods of the object, and the {0} is expressed in the form of key-value pairs.

Key: equivalent to attribute name.

Value: equivalent to attribute value, which can be of any data type. It can also be a method.

It is connected with the key value by':', and each key-value pair is separated by','

The method of getting the object value: variable. property.

2.使用new object创建

使用格式:对象.属性名 = 属性值

获取对象值的方法: 对象.属性

注意:

如果是特殊的属性名的话,不能采用点的形式去引用

使用方法:对象[“属性名”]

删除对象属性,delete obj.name。

2. Create with new object

Usage format: object. Attribute name = attribute value

Method of getting object value: object. property

Note:

If it is a special attribute name, it can't be referenced in the form of dots.

Usage: object ["property name"]

Delete the object property, deleteobj.name.

今天的分享就到这里了。如果您对今天的文章有什么独特的想法,欢迎评论留言,让我们相约明天,祝您今天过得开心快乐!

That's it for today's sharing. If you have any unique ideas for today's article, please leave a comment, let us meet tomorrow, I wish you a happy day!

翻译:Google翻译

本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。

文字&排版|李仕阳

审核|李焕

标签: #js对象foreach