1, the creator of the class of es6 hair:
<! DOCTYPE HTML> <HTML lang = "EN"> <head> <Meta charset = "UTF-. 8"> <title> Object classes and </ title> </ head> <body> <Script> //. 1, Create a class class Star { // this is the constructor constructor (uanme, Age) { this.uname = uanme; this.age = Age; } } // 2, to create the object var ldh = new Star ( 'Andy', 50 ); var = ZXY new new Star ( 'Jacky', 52 is); the console.log (ldh.uname, ldh.age); the console.log (zxy.uname, zxy.age); </ Script> </body> </html>
This creates a simple class.
2. Create a class method:
<Script> //. 1, create a class class Star { // This is the constructor constructor (uanme, Age) { this.uname = uanme; ; this.age = Age } create // class method, the write function does not require keyword // spaced between a plurality of process does not require use form symbols sing (name) { the console.log (this.uname + 'is singing' + ', song:' + name) } } // 2, to create an object var ldh = new Star ( 'Andy', 50); var = ZXY new new Star ( 'Jacky', 52 is); the console.log (ldh.uname, ldh.age); the console.log (zxy.uname, zxy.age) ; ldh.sing ( 'freezing rain'); </ Script>