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