分享興趣,傳播快樂,增長見聞,留下美好!
親愛的您,這裡是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新學苑原創,部分圖檔文字來自網絡,如有侵權請聯系。
文字&排版|李仕陽
稽核|李煥