Getting Started with JavaScript (vi) __java

Source: Internet
Author: User
Object

Objects are the core of our use of JavaScript. Objects in JavaScript are similar in many ways to objects in the real world outside of programming (it doesn't exist, I just assume). In the real world, an object is a "thing" (many of the objects in object-oriented programming are likened to nouns): a car, a table, a chair, and the keyboard I beat. Object owns:

attribute (can be likened to an adjective): The car is red.

method (like a verb in a sentence): The way to start a car may be to unscrew the ignition .

Event : Screwing the igniter caused the car to start the event.

Object-oriented programming (OOP) tries to make programming easier by modeling objects in the real world. Let's create a car simulator. First, we will create a car object that gives it some properties, such as color and current speed. Then we need to create a method: Maybe a Start method to start the car, a break method to slow down the car, in which we need to pass the brakes need to press the strength and size of the message to determine the effect of deceleration. Finally, we need some events, such as a petrol-low event to remind us to refuel the car.

Object-oriented programming involves these concepts. This way of designing software is now very common and popular in many programming areas-but most importantly for us, it is the core of JavaScript and Web programming.

Some of the objects we use are part of the language specification provided by javascript: String objects, date objects, and math objects, and so on. The same JavaScript object is provided in a PDF file or a Web server. These objects provide a number of useful features that can save us a lot of programming time. For example, the Date object allows you to get the current date and time (such as a user's PC) from the client. It holds dates and provides many useful functions related to dates, such as converting a time zone's date/time to another time zone. These objects are often referred to as core objects because they are independent of implementation. The browser itself also provides programming through objects, which allows us to get information about the browser and change the visual effects of the application. For example, the browser provides a Document object that represents a Web page in JavaScript. We can use this in JavaScript to add new HTML elements to the pages viewed by the browser's users. If you've ever used JavaScript in a different host, assuming you use a Windows server, you'll find that JavaScript hosts provide a very different set of host objects that are related to what you do on the server.

You'll find in chapter three that JavaScript allows us to create our own objects. This is a very powerful feature that allows us to use JavaScript to model real-world problems. To create a new object, we need to use a template to develop its properties and methods, which are called classes. A class is similar to an architect's drawing, which specifies what should go where to do something, but it doesn't actually create an object.

n Annotation:JavaScript is an object-based language or an object-oriented language, there are some arguments about this problem. The difference is that object-based languages use objects to program but do not allow coders to use object-oriented programming in their code design. Object-oriented languages not only use objects, but also allow object-oriented approaches to simplify development and code design. JavaScript allows us to create our own objects, but differs from Java, C #, and other classes-based language implementations. However, instead of focusing on what is or is not object-oriented, we should focus on how the object is actually applied in this book, and we will focus on some basic object-oriented programming where needed.

As you read through the book, you will have a deeper understanding of the object: The core object of JavaScript, the browser-supplied object that uses JavaScript to access and manipulate, and the object that creates your own definition. So far, all you need to know is that the objects in JavaScript are "entities" that you can use to add functionality to your Web pages, and they can have attributes and methods. The Math object, for example, has a value in its properties that represents PI, and one of its methods can produce random numbers.

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.