The constructor of prototype/constructor/__proto__.

Source: Internet
Author: User

The literal meaning of 1.constructor is construction. It is a property of the object, and its corresponding value is the "constructor" of the object

1 //constructor of an object instantiated by a constructor function2 functionCMF (n,m) {3    This. n=N;4    This. m=m;5    This. mn=function(){6   return  This. n+ ' | ' + This. M7   }8 }9 varcmf=NewCMF (' C ', ' Q ')TenConsole.log (Cmf.mn ())//C|q OneConsole.log (Cmf.constructor)//CMF (n, m) A //Here you can see the CMF () instance of the CMF () object, the constructor of which is its intrinsic property.  -  - //Ii. constructor of basic data Types the varyi=154 -Console.log (Yi.constructor)//Number () - varLi= "Qdz" -Console.log (Li.constructor)//String ()

Constructor of the 2.1 prototypes

1 functionCMF (n,m) {2    This. n=N;3    This. m=m;4    This. mn=function(){5   return  This. n+ ' | ' + This. M6   }7 }8 9cmf.prototype.jn=function(){Ten   return  This. m+ "!" + This. N One } A varcmf=NewCMF (' C ', ' Q ') -Console.log (Cmf.jn ())//Q!c -Console.log (Cmf.prototype)//CMF {jn=function ()} theConsole.log (typeofCmf.prototype)//Object -Console.log (Cmf.prototype.constructor)//CMF (n, m) - //It is shown above that the constructor of the constructor prototype points to the constructor function. How do you understand that the prototype of the constructor is an obj, and what does this obj consist of? is its constructor constructor. 

2.2 Constructor of the basic data type

  string.prototype.cf=function(n) {   /// to String.prototype this obj Add method CF, string multiplication             Return    new Array (n+1). Join (this)    }var d= "D"  Console.log (D.CF (///ddddd//  String {cf=function ()}// String () // similar to constructors

The constructor of the

prototype/constructor/__proto__.

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.