Front-End development: object-oriented implementation in object-oriented and JavaScript (i.)

Source: Internet
Author: User

front-end development: object-oriented implementation in object-oriented and JavaScript (i.)Objective:

life, This can not find the object is absolutely No. In our lives, we can not find the object to be scolded, the code is the Same. My friend asked me, "hey, what are you doing ...", I: "i can't find the object!" He: "can You find the object like that?" ”。 I have a black face ...

Needless to say, today Bo mainly chat with you is "object-oriented and JavaScript object-oriented implementation".

Object-oriented understanding:

Object-oriented is a kind of method to understand and abstract the real world, is an advanced program design idea, is a kind of abstract, multi-form design Pattern. We can understand This: "everything is the object", I face it, that is, "object-oriented." For example, in front of a tv, in-depth analysis, what are the features of this TV set?

① It is open or closed;

② it has several buttons, including (open key, volume key, previous program, next program);

③ has a set-top box to receive data

  The concept of a class

  now, we think of television as an object, it is abstract is a class , Object abstraction is a class, the materialization of the class is an object, it can be said that the class instance is an object, that is, the class = = Object = = Instance

  Methods of the class

class has a lot of methods, now we can think of TV as a class, what is the method now? switch, volume, program; This is its method, that is, the method of the class; we don't have to worry about what kind of boot-up process the TV is going through, we just need to know that when I press the switch, it will Open.

  Private and public

  The methods that can be accessed by the user are called public methods, and the methods that can only be accessed by the class are called private methods, and yes, it is the data that we cannot control when the TV is receiving information from the TV station, and it calls a method internally. Oh ~ we pressed the switch, and then the switch this method invokes a private method of receiving information, and then the TV is displayed by another private method (displayed on the screen).

  Inherited

  now, I think my TV screen shows a bad effect, ok, for a new one. In the change of time, we can say, Oh ~ Now the TV has a more display, with the display of all the control buttons and control interface (switch, volume, etc.), then we can think that the TV has inherited this new display, it inherits the method of this display, It can now call the display of the display method, the TV display on the new display.

A detailed picture:

Object-oriented implementations in JavaScript (1):

The implementation of object-oriented in JavaScript is not as easy as other oo languages, because it does not directly specify the class identifier and so on, to implement it there are many ways, bloggers for the time being the most common chestnut, the other length is too long, we in the next chapter one by one detailed:

//Create a custom data format                functionDianzan () {//constructor Function} dianzan.prototype= {            //add a method to a classDianzan:function() {alert ("a Great location"); }, budianzan:function() {alert ("cruel refusal"); }            }                varDianzan =NewDianzan ();//An instance (class) was createdDianzan.dianzan ();//Invoke method Point likes

first, we created a constructor and then added two methods to the Constructor's prototype, and finally, We created a dianzan example (class), and then called the Point-like method; with the above logic, do you understand?

Summarize:

In the next chapter, we continue to understand the object-oriented in javascript, which is far less complex than imagined. Figuring out the principles inside, I think it's a very meaningful thing for EVERYONE.

---------------------------------------time never stopped its footsteps, how can you stop---------------------------------------

My number: Qq:

Welcome all kinds of technical discussion, if you have to build station needs, Welcome to contact;

(reproduced Please specify the Source)

Front-End development: object-oriented implementation in object-oriented and JavaScript (i.)

Related Article

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.