Learning EMACSCRIPT6 New Features

Source: Internet
Author: User

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

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.