Jump to content

ECMAScript 6, alias JavaScript 2015


Dad72
 Share

Recommended Posts

Hello,

I just discovered ECMASscript 6 that I find really great. On can now use the term 'class' to 'constructor' can assign variables in the parameter functions, use static functions, constant, extend the 'class' very easily, use 'let' instead of 'var' and others.

I think the future versions in preparation ECMASscript 7 will bring even more opportunities: function public, private, protected ... typing the valiable with int, float...

So, I think tapuscript will used less in the future. Javascript makes a great leap forward for web applications. I'm going to convert my project with the new ECMAScript syntax 6.

What do you think ECMAScript 6 for those familiar?

Link to comment
Share on other sites

I actually switched from ES6 to TypeScript recently.  I have been working in ES6 for over a year.  With ES6 I was using babel, so the generated javascript would run on older browsers and it was a massive improvement over vanilla javascript.  What I found in addition to the ES6 language benefits that TypeScript gave me additional benefits like Interfaces (instead of ES6/javascript conventions), discriminated unions, enumerations, type inference, generics and the code showing more the intent in TypesScript... plus enforcing at compile time my intentions/mistakes that even a good ESLint cannot detect.  I would not say that I have a strong preference for one over the other, but will continue in TypeScript.  I have starter kits for ES6 and TypeScript for BabylonJS in my github repo.

I agree that if JavaScript keeps going as it is going that TypeScript will end up like CoffeeScript, but I'm not sure ES7 is there yet - it's getting the timing right.  Everything ES6 will work in TypeScript, since TypeScript is a superset.

What are the advantages you have found from ES6 over TypeScript or are you switching to ES6 from regular javascript?

Link to comment
Share on other sites

I was using before ES5 and protytype. so switching to ES6 is a good step forward for me. I do not like the typescript made of having to compile. with javascript I just refrech my page to see the results.

 

Link to comment
Share on other sites

I agree ES6 is a good step forward!  There is a lot of new syntax to get used to as well, which is fun to learn.  Just wanted to mention that TypeScript has a -watch option, so you can just refresh the page to see the results, but TypeScript is not as fast as saved javascript to refresh :)  Everybody has their own workflow, so choose what you like best.

Link to comment
Share on other sites

Hi,

just a question ... isn't TypeScript ECMA 6? As you see a difference there, I seem to get something wrong.

So there is 'vanilla JS' (native, simple JavaScript) that is ECMA 5, right?

And then we have TypeScript that follows the conventions of ECMA 6, right?

I also have heard about babel but didn't use it yet. But I thought that is another pendant to TypeScript that also has to be compiled down to vanilla JS.

And I thought that the browsers don't support ECMA6 yet, because JavaScript is still ECMA 5, what is the reason why ES6 has to be compiled.

Right? :-)

Link to comment
Share on other sites

ES6 is javascript and it is a present supported by the browsers.

JavaScript ES6 (This is not typescript)

class actor extends human {
    
    constructor()
    {
        super();
		
    }
	
    createActor(name = "namedefault")
    {
        this.c = null;
        let age = 40;
		
        setTimeout(() => {
            this.c = "v";
        }, 1000);
    }
}

 

Link to comment
Share on other sites

If you want to support downlevel browsers then you can write ES6 and Babel will convert it to ES5.  TypeScript is a superset of javascript, so you can write ES6 in TypeScript - so that is maybe confusing, but the typescript is compiled to javascript.  You can set typescript to target different versions of ECMAScript in tsconfig.json.  ie: "target": "es6".  You can see the ES6 compatibility in charts like this one: https://kangax.github.io/compat-table/es6/

Link to comment
Share on other sites

Or use this code that transforms the ES6 code to ES5 in the fly. (It can be used if the browser does not support ES6)

<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>

<script type="module">
        // code ES6 here
</script>

it is a tool developed by Google.

This can help detect if the browser supports ES6:

var supportsES6 = function() {
    try {
        new Function("(a = 0) => a");
        return true;
    }
    catch (err) {
        return false;
    }
};

 

Link to comment
Share on other sites

23 minutes ago, Dad72 said:

Or use this code that transforms the ES6 code to ES5 in the fly

You can transpile on the fly, however I don't recommend it, especially for games. It has a perfomance impact that it's not needed if the source if transpiled in build time.

Although it's nice that you point it out, because for development and prototyping it can be very helpful.

Link to comment
Share on other sites

16 minutes ago, Dad72 said:

Thanks for the information. I do not think that at the current time it is useful to compile in ES5. Most of the browsers today supports ES6.

If you want to make cordova applications and run it in the native web view.

Older android versions don't support es6 in the webview.

You can always use crosswalk or just ignore those android versions, but there's a use case for es5.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...