1, object-oriented, new class, extends keyword
Object-oriented programming in versions prior to 6.0 3.0
Defines the class var class = function (Name,desc) {this.name = Name;this.desc = Desc;this.display = function () {Console.log ("class:{ Name: "+this.name+", desc: "+this.desc+"} ");}} Instantiate a class an object var a = new Class ("Class", "Define Class Class"), A.display ();//class:{name:class,desc: Defines class class}var B = new Class ("Student", "Define student Class");//Polymorphic B.other = "Parent is class";//overrideb.display = function () {Console.log ("Class:{name:" +this.name+ ", desc:" + This.desc+ ", Other:" +this.other+ "}"); B.display ();//class:{name:student,desc: Define Student class, other: Parent is class}
Object-oriented in 6.0
Defines the class Fatherclass Father{//father constructor method Constructor (Name,desc) {this.name = NAME;THIS.DESC = desc;} Display () {Console.log ("Father:{name:" +this.name+ ", desc:" +this.desc+ "}");}} Define class Sonclass Son extends Father{//son constructor method Constructor (Name,desc,other) {super (NAME,DESC); this.other = Other;} Orverridedisplay () {Console.log ("Son:{name:" +this.name+ ", desc:" +this.desc+ ", Other:" +this.other+ "}");} var father = new father ("Father", "parent object Father"), var son = new son ("Son", "child object Son", "Father Father"); Father.display ();//father:{ Name:father,desc: Parent object Father}son.display ();//son:{name:son,desc: Child object Son,other: Parent is Father}
Does it feel similar to C # or Java? and the integration, encapsulation, multi-state object-oriented three major features perfect support.
2, Generator method (not to be continued)
Learning EMACSCRIPT6 New Features