JavaScript Object-Oriented programming

Source: Internet
Author: User
Tags object object

bad wording.
 function createperson(name,qq) {//Constructors    /* The new constructor will automatically be the new Object object, var this = new object ();     Finally, the new this object is returned, return this; */     This. name=name;//Property name     This. qq=qq;//Properties QQ     This. showname= function() {Alert (' My name is: '+ This. name); } This. showqq= function() {Alert (' My QQ number is: '+ This. QQ); }}varobj=NewCreateperson (' user1 ',' 1234 ');varObj2=NewCreateperson (' User2 ',' 5678 ') alert (Obj.showname = = Obj2.showname);//false/* The showname of the two new build objects are different for new objects, and memory consumption is affected by excessive performance. * /
good wording.
 function createperson(name,qq) {//Constructors     This. name=name;//Property name     This. qq=qq;//Properties QQ}createperson.propotype.showname= function() {Alert (' My name is: '+ This. name);} createperson.propotype.showqq= function() {Alert (' My QQ number is: '+ This. QQ);}varobj=NewCreateperson (' user1 ',' 1234 ');varObj2=NewCreateperson (' User2 ',' 5678 ') alert (Obj.showname = = Obj2.showname);//true/ * At this point the two obj showname are the same * /

Object-Oriented Programming : Add attributes (variables) with constructors, and use prototypes to add methods (functions).
into the prototype, and put it in the constructor differently. Because name, QQ is indeterminate, and the method shown is the same.

Object- oriented : When working with objects, focus only on the functionality provided by the object, without paying attention to its internal details, such as jquery

CSS JavaScript
Class Add to a group of elements at once Prototype
Style Add to one element at a time A method to add to an object

A prototype is equivalent to a class in CSS, adds to a set of elements, and can inherit a common

varnewArray();
class Object
Mold Products (finished)
Array () Arr
Can be new Array () Do not use new arr ()
Array is a die, does not have the actual function, cannot array.push () ARR is a product that is brought to use and can be Arr.push ()
Classes have prototypes that can be Array.prototype Object has no prototype and cannot be Arr.prototype

JavaScript Object-Oriented programming

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.