[library] simulating ES6 Classes in Espruino

Posted on
  • I've just dropped some RegExp check and polyfilled internally what was missing in Espruino, in case you'd like to have ES6 alike syntax for classes, with ES7 ability to compose through mixins/traits, I'd like to link you at this project of mine, called es-class

    The minified version is not hand crafted/compacted explicitly for Espruino, but with plain 3.5kB (1.6kB gzipped) you get granted cross platform compatibility, including the MIPS node version of Arduino Yun, and basically all other JS engines out there I could verify.

    Key features are:

    1. semantic Class({..}) declaration
    2. extends and handy this.super(...) ability
    3. static properties definitions
    4. bonus for mixins/traits via with: [ ... ] plus implements for light checks on expected interfaces

    As Gordon asked me in another thread, you ain't gonna need probably all these features, but maybe you'd like to write some code that looks like modern JS without breaking your Espruino.

    Performance are also as good as vanilla JS, only light overhead is classes definitions, luckily this happens only once at bootstrap so you won't probably notice that.

    All tests are green except those based on ES3 non standard get/set literal objects syntax which is not implemented here, and some tiny instanceof gotcha that will hopefully be solved soon since Gordon has already a bug to work on.

    I hope someone will find it handy.

    Best Regards

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

[library] simulating ES6 Classes in Espruino

Posted by Avatar for WebReflection @WebReflection

Actions