HTML5 elimination Block Game summary-Object

Source: Internet
Author: User

In just 2 weeks, did 2 projects, although the time is very compact, very tired, but I think this is very substantial, in each of the actual combat project in the process can find a lot of common problems, but also only the actual operation of the project, in order to let me learn the knowledge ingenious, and can quickly adapt to the actual work of the project.

This week is a small game, a little people based on the same color to eliminate blocks of the project, although the time to do the game is very short, but I think I harvest quite abundant, continuous learning, let me feel more practical, although tired, I also feel very worthwhile, this project mainly let us understand and use the concept of object-oriented programming.

object is an abstract concept, is a way of thinking in the face of people, people have characteristics, such as objects in the attributes, and people have behavior, such as the method of the object;

But how to understand an abstract thing, in my understanding that the object is like a car factory drawings, he is only a conceptual thing, can only provide ideas, let us have a clear direction, and to let the object in reality-that is, the creation of an instance of the new one, which is the JS object to produce an instance of the important point, We usually call the new one (var objs = new obj ()); the example here is like a car factory in every workshop production of parts, according to the drawings to produce a variety of parts, but the light has a drawing is not able to produce parts, here also need a most important thing, That is the machine needed to produce this part, which is similar to the prototype in JS, which is an important tool to produce an example.

So in JS, how to produce an instance? Here, you need to use the prototype command (Obj.prtottype. properties);

Therefore, the relationship between the object-prototype-instance is straightforward and understandable.

In addition to object-oriented learning, the game also learned that the most important aspect of object-oriented is inheritance

What is inheritance, inheritance is the repeated property code in our object is encapsulated, can take full advantage of the extensibility of resources and reuse;

is set to the parent element, and then when there are child elements, the child elements inherit some of the attributes from the parent element, and there are two ways to do this:

1. Object impersonation (to verify that a true child element is only printed at the back: obj.instanceof parent element);
Name, age is the attribute of the parent element;
1. Method 1:
1. This.inhert=obj;
2. This.inhert (name, age);
3. Delete This.inhert;

2. Method 2:obj.call (This,name,age)
3. Method 3:obj.apply (This,[name,age])
4. The difference between call and apply is the difference between the last pass parameter, one is the array one is separated by commas;
2. True Inheritance Law
1. Child elements. prototype = new parent element

HTML5 elimination Block Game summary-Object

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.