JS Learning: First week--no.3 object-oriented

Source: Internet
Author: User
Tags hasownproperty

"Object-oriented fundamentals"
    1. Encapsulation: For the same function code, we only need to encapsulate once, and then encounter similar functions, just call it, without rewriting, avoid a lot of redundant code.
    2. Characteristics of objects: methods and properties;
    3. Object-oriented features:
    • Encapsulation: low coupling high cohesion;
    • Inheritance: Subclasses inherit the properties and methods of the parent class, but do not affect the function of the parent class;
    • Polymorphism: Mainly includes overloading and rewriting;
    • Note: ① Overload: JS does not have a strict sense of overloading, but there are similar overloaded functions, different parameters can be used to achieve different functions,
② rewrite: Subclasses can override method properties of the parent class; "Singleton mode" (essentially an object)
    1. Advantages and disadvantages of the singleton model:
(1) To achieve modular development, is the simplest modular development ① the mutual invocation between different modules: Object name. property name; ② call between this mode: this. property name; (2) Avoid full Conflicts of local variable names Note: The introduction of each module requires attention to the order of introduction, the order of introduction in accordance with the interdependence between the various modules before and after the arrangement.
    1. Modular development: For a large project, the project portfolio is assigned to different engineers for simultaneous development, and when all the engineers are developed, the project is subsequently merged.
"Engineering Mode" (essentially the encapsulation of ordinary functions) three steps: (1) The introduction of raw materials-creating an empty object, (2) Processing object-Output object, adding properties and methods to the object, (3) Output product-return object, return object, advantages and disadvantages: Excellent: Avoids the large number of redundant code in the singleton mode, carries on the encapsulation of the system; Missing: Different from the system built-in classes; "Constructors" (1. Capitalized, 2.;3. Private properties and methods are stored in the constructor)
    1. Different from the factory model;
          1) call different:                Factory mode: Call time, just normal function call &N Bsp               constructor mode: New   Creatperson ();          2) function body does not With;                Factory model Three steps: Create object, Process object, return object;            & nbsp   Constructors: Only processing objects, because the system defaults to creating objects and returning objects      2. Constructors: You can create a custom class, and you can make a new instance of it, and the constructor primarily deals with instances and classes;     3. Details: This is a new instance of the ① constructor, and the ② constructor stores all private properties and methods;   ③ constructor system returns this by default and is not recommended for manual return if you do not want to manually return it:         A: Manually returned string type: No effect on properties and methods on previous instances;        B:   The reference data type is returned manually: the properties and methods on the previous instance are overwritten, the instance cannot call the properties and methods   The  ④ constructor is called again, if there are no arguments, the parentheses can omit the;   ⑤ constructor is the class and instance in dealing with;    ⑥ with Var in the constructor has nothing to do with the instance, the instance is only related to this.xxxx; prototype Mode 1. Prototype mode: Mainly classes   instances   and prototypes; 2. Basic knowledge of prototypes:☆☆☆☆☆☆   ① each function data type (normal function, Class), there is an attribute, called prototype, is an object;   ②prototype This object, naturally comes with a property, COnstructor points to the current class;   ③ each object data type (normal object, prototype, instance) has an attribute called __proto__; a prototype that points to the class to which the current instance belongs; 3. Object. Prototype the above properties and methods:   hasownproproperty determine whether it is private;    Judging Public properties: Function haspubproperty (attr, obj)  {    Return attr in  obj && !obj.hasownproperty (attr);}   isPrototypeOf Determine whether the previous object is on the prototype chain;     propertyIsEnumerable4. Reflex Knowledge Points: 1) Constructors: properties and methods in constructors are private;  2) constructors are instances of this;    3) The properties and methods on the prototype are public;   4) constructor mode: instance and class;   5) prototype mode: Instance class   prototype; 6) __prototype__: Prototype chain; 7) when giving   class. prototype={}   When this is assigned, constructor points to the problematic "prototype chain" definition: If you want to find   The object. Property name: 1. A lookup is made in its own private space, and if found, the x is a private attribute 2. Not found: by __proto__ to the current instance of the class of the prototype to find, if found, the description is a common attribute; 3. Cannot find: Continue through __proto__ To find the prototype of the class to which the current instance belongs, it will continue to be found through __proto__. Objectinstanceof: The detection instance belongs to a class "X" in Fn: Determines whether a property is again on the object, including private and common attributes;. hasOwnProperty ( "): To determine whether it is a private attribute; __proto__ is forbidden under IE;" The benefits of learning prototype chain mode ": 1) understand the composition of the system-provided classes, 2) can provide more learning opportunities, such as  ,ary.keys do not know; You can expand your knowledge by querying. ; 3) can add more methods to the system's built-in classes to facilitateCo-developers in the team. "Coupling and cohesion" coupling: Also known as the inter-block connection. A measure of the degree of connection between modules in a software system structure. The tighter the connection between the modules, the stronger the coupling, the less the module's independence. The coupling between the modules depends on the complexity of the interface between the modules, the mode of invocation and the cohesion of the information: Also known as intra-block contact. A measure of the functional strength of a module, a measure of the degree to which each element within a module is bound to each other. The more cohesive the elements within a module (between the names and the program segments), the higher the cohesion is. The so-called high cohesion refers to a software module is composed of strong correlation code, only responsible for a task, that is, the single principle of responsibility is often said. Coupling: A measure of the degree of interconnection between different modules within a software structure. For low-coupling, the superficial understanding is: a complete system, between the module and the module, as far as possible to make its independent existence. In other words, let each module, as far as possible, complete a specific sub-function independently. The interface between modules and modules is as small and simple as possible. If the relationship between the two modules is more complex, it is better to consider the further module division first. This facilitates modification and combination.  
    1. The class array contains two kinds: 1) arguments;2) elements collection;

JS Learning: First week--no.3 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.