Learn Javascript Note 1 Javascript Object 1

Source: Internet
Author: User

Learn Javascript Note 1 Javascript Object 1

I have studied Js for a while before. Now I want to look at it again. It seems like new knowledge, indicating that I am not very good at Js (it is very bad, it has never been better, hey). Here, review

If you see it unfortunately, it's just your note.

The object-oriented idea in Js is absolutely very important. If you have read the code of great gods, you will know how important the object-oriented idea in Js is.

All things in JavaScript are objects: String, Number, Array, Date, and so on.

In JavaScript, objects are data with properties and methods.

Attributes and Methods

1. attributes are values related to objects. 2. The method is an action that can be executed on an object.

For example, cars are objects in real life.

Attributes of a car:

Car. name = Fiat car. model = 500 car. weight = 850 kg car. color = white

Car methods:

Car. start () car. drive () car. brake ()

In JavaScript, the object is data (variable) and has attributes and methods. When declaring a JavaScript variable:

       var txt = new String("Hello World");
Here, the String object has built-in properties and methods: txt. length (attribute) txt. indexOf ("World") (method)

Create a JavaScript Object (1) person = new Object ();
Person. firstname = "John ";
Person. lastname = "Doe ";
Person. age = 50;
Person. eyecolor = "blue"; (2)
Person = {firstname: "John", lastname: "Doe", age: 50, eyecolor: "blue "};

(3) Use the object constructor

     function person(firstname,lastname,age,eyecolor){          this.firstname=firstname;          this.lastname=lastname;          this.age=age;          this.eyecolor=eyecolor;      }







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.