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

Example Analysis of JavaScript object, object property and object method

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the JavaScript object, object properties, object method example analysis, the article introduces in great detail, has a certain reference value, interested friends must read it!

The JavaScript variable is a container for data values.

This code assigns a single value (porsche) to a variable named car:

Var car = "porsche"

Objects are also variables. But the object contains many values.

This code assigns multiple values (porsche, 911, white) to a variable named car:

Var car = {type: "porsche", model: "911", color: "white"}

Values are written as name: value pairs (names and values are separated by colons).

The JavaScript object is a container for named values.

Object attribute

(in the JavaScript object) name: value pairs are called properties.

Var person = {firstName: "Bill", lastName: "Gates", age:62, eyeColor: "blue"}

Attribute value

FirstName Bill

LastName Gates

Age 62

EyeColor blue

Object method

Objects can also have methods.

Method is an action performed on an object.

Method is stored in the property as a function definition.

Attribute value

FirstName Bill

LastName Gates

Age 62

EyeColor blue

FullName function () {return this.firstName + "" + this.lastName;}

Method is a function that is stored as an attribute.

Example

Var person = {

FirstName: "Bill"

LastName: "Gates"

Id: 678

FullName: function () {

Return this.firstName + "" + this.lastName

}

}

These are all the contents of the article "sample Analysis of JavaScript objects, object Properties, and object methods". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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