Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create objects and what role they play in web front-end development

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article examines "how to create objects and what role they play in web front-end development". The content is detailed and easy to understand, and friends who are interested in "how to create objects and what role they play in web front-end development" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's learn more about how to create objects and what role they play in web front-end development with the editor.

What is the object?

The type of object is Object.

Everything in JavaScript is an object: strings, numeric values, arrays, functions.

Everything is an object in javaScript

Explain the object in a more official language:

What is an object is actually a type, that is, a reference type. The value of the object is an instance of the reference type. In ECMAScript, a reference type is a data structure that organizes data and functions together. It is also often called a class, but there is no such thing in ECMAScript. Although ECMAScript is an object-oriented language, it does not have the basic structures such as classes supported by traditional object-oriented languages.

What if you want to have a date?

Create objects: (create two ways)

1.New, an object comes out.

Var obj = new Object ()

Found the object > the first thing that comes to mind is attributes.

Add an attribute to the object

Obj.bianmei=' wow is really getting prettier.

Expand:

Obj.fn=function () {

Code block

}

Obj.fn ()

The property of obj can be a function

The pointer this in the obj function points to the obj object

two。 Create objects literally:

Var obj= {}

Add an attribute to the object

Key-value pair

Obj= {

Jian:zhi

}

Take the value through the key; press the key of the keyboard, the corresponding value will appear; this is the same as the value principle of the object; take the value through the key

Of course, you can also put functions in such objects, and the functions run in the same way as before, and the this pointer in the object also points to the current object.

Delete the properties of an object

Delete obj.jian

You can write a little exercise yourself, create an object of your own by string concatenation, and define a method in the object to make it pop up.

1. One's own name

two。 One's age

3. One's own hobby

4. A small summary

This is enough about how to create objects and what role they play in the front-end development of web. I hope the above content will improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report