Learn JavaScript notes 1 JavaScript objects 1

Source: Internet
Author: User

Before learning a period of time JS, and now look, feel like a new knowledge, explain their grasp of JS is not very good (is very bad, never better, hey), here, in the review

If you eldest brother elder sister unfortunate see,, the forehead this is only own notes.

The idea of object-oriented in JS is absolutely important, if you look at the code of the Great God, you will know how important the idea of object-oriented in JS is.

Everything in JavaScript is an object: A string, a number, an array (array), a date, and so on.

In JavaScript, objects are data that owns properties and methods.

Properties and Methods

1, the property is the value associated with the object. 2. The method is an action that can be performed on the object.

For example, a car is a real-life object.

Properties of the car:

car.name = Fiat Car.model = car.weight = 850kg car.color = White

Method of Car:

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

in JavaScript, objects are data (variables) that have properties and methods. when declaring a JavaScript variable:

       var txt = new String ("Hello World");
Over hereThe String object has built-in properties and methods:txt.length (property) Txt.indexof ("World") (method)

Creating JavaScript Objects (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) using the Object Builder

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






 


Learn JavaScript notes 1 JavaScript objects 1

Related Article

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.