JavaScript Object-oriented

Source: Internet
Author: User

Object-oriented: without understanding the principle of the case, will use the function, do not pay attention to internal details, is a general idea

Object: Black box does not understand the internal structure, know the surface of the various operations

Object-oriented Programming OOP:

    • Features: Abstraction (grasping core issues),
    • Encapsulation (regardless of internal implementation, only features are considered),
    • Inheritance (genetic parents and children inherit some properties and methods from the parent class, and can have their own new method)

Multiple inheritance polymorphism

Objects are made up of properties and methods

  • Properties-Variables: state static
  • Method-Function: Process dynamics
    <!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <title></title></Head><Body><Scripttype= "Text/javascript">    vara=7;//the variable is free, not belong to anyonealert (a); vararr=[1,2,3,4,5,6]; ARR.A= A;//property is not free and belongs to an objectalert (ARR.A); functionAA () {alert ('ABC');//function: Free} AA (); Arr.aa= function() {alert ('ABCD');//method: Non-free belongs to the object} arr.aa ();</Script></Body></HTML>

    Results: 7 ABC ABCD

  • This: The current method of the object in which the event occurred.

    <Scripttype= "Text/javascript">    vararr=[1,2,3,4]; ARR.A= A; Arr.show=function() {alert ( This. a); } arr.show ();</Script>

    12

    <type= "Text/javascript">    window.show=  function() {    alert (this);    }    Show (); </ Script >

    Object window The current method belongs to who belongs to window

  • You can no longer add methods or properties to the system object, otherwise overwrite existing methods and properties
  • Object objects have no things
<Scripttype= "Text/javascript">   varobj=NewObject (); Obj.name='Blue'; OBJ.QQ='930260035'; Obj.showname= function() {alert ('My name is:'+ This. Name); } obj.showqq= function() {alert ('my QQ is:'+ This. QQ);    } obj.showname (); OBJ.SHOWQQ ();</Script>

<Scripttype= "Text/javascript">    functionCreateperson (name,qq) {//constructor Function       //Raw Materials        varobj=NewObject (); //processingObj.name=name; OBJ.QQ=QQ; Obj.showname= function() {alert ('My name is:'+ This. Name);        }; OBJ.SHOWQQ= function() {alert ('my QQ is:'+ This. QQ);        }; //Factory        returnobj; }    varobj=Createperson ('Blue','54546466');    Obj.showname ();    OBJ.SHOWQQ (); varObj2=Createperson ('Zhang San','555555555');    Obj2.showname (); OBJ2.SHOWQQ ();</Script>
    • Disadvantages of the factory approach: no new function duplication leads to wasted resources

JavaScript Object-oriented

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.