(1) JavaScript objects

Source: Internet
Author: User

JavaScript objects are data that owns properties and methods.

In JavaScript, almost all things are objects.

An object is also a variable, but an object can have more than one value.

For example:

var person = {firstName: "John", LastName: "Doe", Age:50, Eyecolor: "Blue"};
Object Properties

It can be said that a JavaScript object is a container for a variable, but a JavaScript object is generally considered a container for key-value pairs. The form is Name:value (the key is separated from the value with a colon). Key-value pairs are called object properties in the object.

Accessing Object Properties

Object properties can be accessed in two ways.

person.nameperson["name"]
Object methods

The method of the object defines a function and stores it as an object's property.

The object method is called (as a function) by adding ().

The instance accesses the FullName () method of the Person object:

1 name = Person.fullname ();
Accessing Object methods

You can create method properties in objects by using the following methods

1 methodName:function() {// actual code}

Object methods can be accessed through the following syntax

1 objectname.methodname ();

(1) JavaScript objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.