JS object-oriented oop Simple description

Source: Internet
Author: User
<script type= "Text/javascript" >
var txt= "Hello world!"
document.write (txt.length)//Use the Length property of the string object to calculate the number of characters in the string, output: 12
</script>
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.touppercase ())//uses the toUpperCase () method of the string object to display the uppercase text. Output as: Hello world!
</script>

Classes and objects

Objects (object) are an instance of class (instance). If the object is compared to a house, then class is the design drawing of the house. So the focus of object-oriented programming is the design of classes, not the design of objects. A class can encapsulate data and functions together, where a function represents the behavior (or service) of a class. class provides keywords public, protected, and private to declare which data and functions are publicly owned, protected, or private.

This can achieve the purpose of information hiding, that is, let classes only expose what must be known to the outside world, and hide everything else. We can not abuse the packaging function of the class, do not treat it as a hotpot, everything thrown in.

When designing a class, "behavior-centric", that is, first consider what kind of function the class should provide.

It is easy to design an orphaned class, and it is difficult to design the base class and its derived classes correctly. Because some do not know the concepts of "inheritance" (inheritance), "combination" (composition), "polymorphism" (polymorphism).

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.