1. The function prototype property

< Body > 
! <- 
prototype property 1. function (FIG.) 
  * Each function has a prototype property that points to a default null object Object (i.e. referred to as: the prototype object ) 
  * prototype object has an attribute constructor, it points to the function object 
2. Add attribute (method usually) to the prototype object 
  * function: a function of all instances of objects automatically have the prototype property (method) 
-> 
< Script type = "text / JavaScript" > 

  // per functions has a prototype property that points to a default null object Object (i.e. referred to as: prototype object) 
  the console.log (Date.prototype, typeof Date.prototype)
   function Fun () { // Alt + R & lt Shift + (weight named the rename) 

  } 
  console.log (Fun.prototype)   // default points to an empty object Object (not our property) 

  //Prototype object has an attribute constructor, which points to the function object 
  the console.log (Date.prototype.constructor === a Date) 
  the console.log (Fun.prototype.constructor === Fun) 

  // to add attributes prototype object (typically method) ===> instance of an object can be accessed 
  Fun.prototype.test =  function () { 
    the console.log ( ' Test () ' ) 
  } 
  var Fun =  new new Fun () 
  fun.test () 

</ Script > 
</ body >

 

Guess you like

Origin www.cnblogs.com/lucy-xyy/p/11819971.html