This is I picked up on the internet, posted up to learn with everyone. Applying object in JavaScript (1)

Source: Internet
Author: User
Tags html form object model
Applying object in JavaScript
JavaScript is a client-side scripting language that, in most cases, is used to make objects that fly on a Web page, or to validate the legality of input data in an HTML form. But if you dig deeper than these images, you will find that there are many other uses for this easy language to learn. For example, the Object-oriented (object) architecture in JavaScript. You don't know what it is to be object-oriented in JavaScript, right? No matter, please follow me.
JavaScript's object model provides less functionality and flexibility than Java and Perl languages, but you'll soon see that even limited functionality can be handy. And, if you think about it a little more, developers using JavaScript objects can significantly reduce the time spent on code development and testing. Of course, this exquisite and wonderful Web page can also win the respect of colleagues and the admiration of the beautiful girl next door:
I. Overview of objects
Before you introduce the object structure, what do you have in the world for quick browsing of objects?
In JavaScript, an object builder is just a set of program statements that are used to accomplish a special task: They set the basic rules for an object, and specify what it can and cannot do. A typical object builder contains variables and functions, and as a template, produces a special example of that object.
Each object constructed from a template has some characteristics or "properties", and there are predefined functions or "methods" that directly correspond to variables and functions in the object definition.
After the object is defined, JavaScript allows you to generate a number of examples based on your own needs. Each of these examples is a completely separate object, has its own properties and methods, and can operate independently of other objects.
Now you may wonder: Is this a bit superfluous? Because JavaScript allows you to create custom functions and use them where you need them in your code. Isn't that enough? Yes, if you want to generate only one object, then the function can accomplish this task.
However, you often generate more than one example for an object. For example, multiple menu trees, multiple image exchanges. In this case, it is best to use objects so that each example has its own variables and functions that can be manipulated without affecting other variables in the program.
Objects also help keep your code modular. You can define an object constructor in a separate file, and only include the file in the page that is used to the object. This greatly simplifies the modification of the code, as it is possible to add new functionality to all the generated objects by editing only one file.
Two. Define Object builder Sumthing
You've probably met a JavaScript object before, like the following code creates a new example of an image object:
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.