Javascript is a headache

Source: Internet
Author: User

When thinking about C ++'s object-oriented architecture, it takes some time to solve many problems. However, many JavaScript problems have been unclear recently, but they may be difficult to understand.

 
Function shape () {This. area = function () {};} Function Point () {This. X = 0; this. y = 0;} var P = new point; console. log (P. prototype); // For undefineconsole. log (P. constructor); // why is it the functionconsole pointing to the point. log ("-----------------------------"); p. prototype = new shape (); console. log (P. area); // Why is it undefine? I didn't set the prototype object. prototype = new shape (); console. log (P. area); // TMD still does not work. I have set the prototype object Ah point. prototype . Area = function () {}; console. log (P. area); // your mom, why? Var P2 = new point; console. log (p2.area); // I operate, then you can @ # ¥ % ...... &*(

 

Output:

 
Undefinedfunction point () {This. x = 0; this. Y = 0;} ----------------------------- undefinedundefinedundefinedfunction (){}

 

when can I find out! I have read a bunch of articles . I am a programmer with more than 5 years of programming experience in TMD, I am still proficient in object-oriented programming. I planted JavaScript. Don't give your brother a piece of Code : That's right. You know how to write it, but brother cannot figure out his internal relationships. Are there any problems !!! Who can draw a picture to draw the reference relation, idle object, and type object above, so let me stick it once.

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.