JS in the constructor function:
//constructor FunctionfunctionDog (Sex) {//Public Properties This. Sex =sex; This. Name = ' Blog '; //Private Properties varSound = ' Wang Woo '; varthat = This; //Private Methods functionShowName () {console.log (that.name); } showname ();} /** Add public properties/public methods to constructors * The prototype * Prototype property is required: gives you the ability to add properties and methods to objects. * Adding a member to prototype will add the new method to the bottom of the constructor*///Public PropertiesDog.prototype.color = ' Red ';//Public MethodsDog.prototype.run =function() { return"Ten km/h";} /** Add static Properties/static methods to constructors * Note some special properties: If name defaults to the method name, modifying this static name may always be the method name*///Static Propertiesdog.address = ' Mars ';//Static MethodsDog.showsex =function(dog) {returnDog.sex;}//instantiation ofvarDog1 =NewDog (' Boy '));//1. Calling public properties/methodsConsole.log ("Color:", Dog1.color)//RedConsole.log ("Run:", Dog1.run ())//ten km/h//2. Calling private properties/methodsConsole.log ("Address:", dog1.constructor.address)//MarsConsole.log ("Showsex:", Dog1.constructor.showSex (DOG1))//Boy
3. Attribute Method view
Console.log ("constructor:", Dog1.prototype)//UndefindConsole.log ("prototype-dog-:", Dog.prototype)//{Object}Console.log ("constructor:", Dog1.constructor)//function () {}Console.log ("constructor-dog-:", Dog.constructor)//function () {}
JavaScript's constructor