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.