Skip to content

Instantly share code, notes, and snippets.

@pvorb
Last active December 19, 2015 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvorb/6031934 to your computer and use it in GitHub Desktop.
Save pvorb/6031934 to your computer and use it in GitHub Desktop.
Draft for a perfect Compile-to-JavaScript language

Ideas for a Compile-to-JavaScript language

  • val for constant values (maybe const?)
  • Function definition with fn keyword instead of function (maybe def?)

  • Anonymous function definition with => notation

    E.g.: (a, b) => { return a * b; }

  • Error on using undefined variables

  • Error on defining variables without modifier

  • == will always become ===

  • if (a == undefined) // ... will translate to if (typeof a === 'undefined') // ...

  • Number literals may also contain _ characters to separate blocks for better readability.

    E.g.: val a = 0x1000_0011

  • Mandatory semicolons after every expression

But in general: keep it simple! JavaScript doesn't have to change that much to become much simpler.

// Some example JavaScript code
var a = 5;
var b = a * 10;
function Person(name, dateOfBirth) {
this.name = name;
this.dateOfBirth = dateOfBirth;
}
Person.prototype.toString = function() {
return this.name + ", " + this.dateOfBirth;
};
// And the corresponding code in this new language
val a = 5;
val b = a * 10;
fn Person(name, dateOfBirth) {
this.name = name;
this.dateOfBirth = dateOfBirth;
}
Person.prototype.toString = () => {
return this.name + ", " + this.dateOfBirth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment