JavaScript Advanced (4) analysis of several special cases---

Source: Internet
Author: User

Situation One

function AAA () {  this. Say = "haha";    = "Own"; var New AAA (); Console.log (Obj.say);     // "haha"console.log (obj.own);    // undefined // "Own"

Situation Two

varperson =function (){   This. pro= "QQQ";  This. Sayword =function (){    return789; };}varCarl =NewPerson (); Console.log (Carl.pro); //"QQQ"Person.prototype.newPro = 123; Console.log (Person.sayword); //undefined here means that the private property is accessed, not the public property of the this declaration within the functionConsole.log (Carl.newpro);//123Console.log (Carl.sayword);//function () {return 789;}

Situation Three

functionobj () {varA = 444;  This. B = 456; C=function (){    varQ = 123; } d=456; OBJ.E=741;}varNew_obj =Newobj (); Console.log (NEW_OBJ.A);//undefinedConsole.log (NEW_OBJ.B);//456 Accessing the public properties defined with thisConsole.log (NEW_OBJ.C);//undefinedConsole.log (NEW_OBJ.D);//undefinedConsole.log (NEW_OBJ.E);//undefinedConsole.log (OBJ.A);//undefinedConsole.log (OBJ.B);//undefinedConsole.log (OBJ.C);//undefinedConsole.log (OBJ.D);//undefinedConsole.log (OBJ.E);//741
    • After defining a function, pass ". "Number for its added properties and functions, through itself can access to OBJ.E, but this function created by the instance of access to the knife, we call this property static variable, Alive is a static property

Situation Four

functionobj () { This. A = 123;  This. B = 456;  This. C =function(){    return1234; }  }varObj1 =Newobj (); obj1.a= 456; obj1.c= {};//Check whether the modification was successfulConsole.log (obj1.a);//456Console.log (obj1.c);//ObjectvarObj2 =Newobj ();//Check whether the modification was successfulConsole.log (obj2.a);//123Console.log (OBJ2.C);//function () {return 1234;}
    • As a result, the Obj1 property modification has no effect on the properties in Obj2, that is, the property in Obj1 and Obj2 has the same name but not a reference

JavaScript Advanced (4) analysis of several special cases---

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.