Ad
Code
Diff
  • function monteCarlo() {
      return new Promise(function (resolve, reject) {
        reject({server: 'down'});
      });
    }
    
    async function main() {
    
      // converter para ES6
      const results = await monteCarlo().catch(error => console.log(error));
      
      return true;
    }
    • function monteCarlo() {
    • return new Promise(function (resolve, reject) {
    • reject({server: 'down'});
    • });
    • }
    • async function main() {
    • // converter para ES6
    • const results = await monteCarlo();
    • const results = await monteCarlo().catch(error => console.log(error));
    • return true;
    • }
Code
Diff
  • function monteCarlo() {
      return new Promise(function (resolve, reject) {
        resolve([{
          titulo: 'UOL - O Melhor conteúdo'
        }]);
      });
    }
    
    async function main() {
    
        let response = await monteCarlo()
        console.log(response)
      
      return true;
    }
    • function monteCarlo() {
    • return new Promise(function (resolve, reject) {
    • resolve([{
    • titulo: 'UOL - O Melhor conteúdo'
    • }]);
    • });
    • }
    • async function main() {
    • // converter para ES6
    • monteCarlo().then(function(response) {
    • let response = await monteCarlo()
    • console.log(response)
    • });
    • return true;
    • }
Code
Diff
  • const main = () => {
    
      let a = [1, 2, 3];
      
      let b = [4, 5, 6];
      
      let c = [7, 8, 9];
    
      // converter para ES6
      var d =  [...a, ...b, ...c];
      
      return d.join(',');
    }
    • const main = () => {
    • let a = [1, 2, 3];
    • let b = [4, 5, 6];
    • let c = [7, 8, 9];
    • // converter para ES6
    • var d = a.concat(b).concat(c);
    • var d = [...a, ...b, ...c];
    • return d.join(',');
    • }
Code
Diff
  • class Component {
      constructor(dom) {
        console.log('Parent class constructor executed!');
        this.dom = dom;
      }
      
      onCreate() {
        return true;
      }
    }
    
    class Collection extends Component {
      constructor(dom, bool) {
        return super()
      }
    }
    • class Component {
    • constructor(dom) {
    • console.log('Parent class constructor executed!');
    • this.dom = dom;
    • }
    • onCreate() {
    • return true;
    • }
    • }
    • class Collection {
    • //
    • class Collection extends Component {
    • constructor(dom, bool) {
    • return super()
    • }
    • }
Code
Diff
  • class Component {
      constructor(dom) {
          this.dom = dom;
      }
      
      onCreate() {
        console.log('onCreate from parent class');
        return 'missing';
      }
      
      static on(event, callback) {
        callback();
      }
      
      async emit(event, data) {}
    }
    
    class Title extends Component {
      onCreate() {
        super.onCreate();
        return 'super!';
      }
    }
    
    
    • class Component {
    • constructor(dom) {
    • this.dom = dom;
    • }
    • onCreate() {
    • console.log('onCreate from parent class');
    • return 'missing';
    • }
    • static on(event, callback) {
    • callback();
    • }
    • async emit(event, data) {}
    • }
    • class Title extends Component {
    • onCreate() {
    • super.onCreate();
    • return 'super!';
    • }
    • }
Code
Diff
  • class Component {
      constructor(dom) {
        this.dom = dom;    
      }
      
      onCreate() {
        return this.dom;
      }
    
      
      
    }
    • function Component(dom) {
    • this.dom = dom;
    • this.onCreate = function() {
    • class Component {
    • constructor(dom) {
    • this.dom = dom;
    • }
    • onCreate() {
    • return this.dom;
    • }
    • }
Code
Diff
  • {
      function todo() {
        return 'Walk';
      }
      
      // reescrever em ES6
      {
      
        function todo() {
          return 'Run';
        }
      
      }
    }
    
    • function todo() {
    • return 'Walk';
    • }
    • // reescrever em ES6
    • (function() {
    • {
    • function todo() {
    • return 'Run';
    • return 'Walk';
    • }
    • // reescrever em ES6
    • {
    • function todo() {
    • return 'Run';
    • }
    • }
    • })();
    • }
Code
Diff
  • // reescreva usando ES6
    
    var prop = 'myProp';
    
    var obj = {
      [prop]: 123,
      myFunc() {
        return this[prop];
      } 
    };
    
    obj.myProp;
    • // reescreva usando ES6
    • var prop = 'myProp';
    • var obj = {
    • myFunc: function() {
    • [prop]: 123,
    • myFunc() {
    • return this[prop];
    • }
    • };
    • obj[prop] = 123;
    • obj.myProp;
Code
Diff
  • var title = 'UOL - O melhor conteúdo';
    
    var share = {
      fb: {
        title
      },
      twitter: {
        tweet: title
      }
    };
    • var title = 'UOL - O melhor conteúdo';
    • var share = {
    • fb: {
    • title: title
    • title
    • },
    • twitter: {
    • tweet: title
    • }
    • };
Code
Diff
  • let results = [
      {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]},
      {materia: {conteudo: {}}, tags: [3, 2]},
      {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]},
    ];
    
    for (const {materia: {conteudo: {titulo = "Brasil"}}} of results) {
      console.log(titulo);
    }
    • let results = [
    • {materia: {conteudo: {titulo: 'São Paulo'}}, tags: [1, 2, 3]},
    • {materia: {conteudo: {}}, tags: [3, 2]},
    • {materia: {conteudo: {titulo: 'Rio de Janeiro'}}, tags: [3, 2]},
    • ];
    • for (const result of results) {
    • let titulo = result.materia.conteudo.titulo || 'Brasil';
    • for (const {materia: {conteudo: {titulo = "Brasil"}}} of results) {
    • console.log(titulo);
    • }
Code
Diff
  • const bg = 'gray';
      
    const css = `
    <style>
    body {
      background: ${bg};
      color: black;
    }
    </style>
    `
    • var bg = 'gray';
    • var css = '' +
    • '<style>' +
    • 'body {' +
    • ' background: '+ bg + ';' +
    • ' color: black;'
    • '}' +
    • '</style>';
    • const bg = 'gray';
    • const css = `
    • <style>
    • body {
    • background: ${bg};
    • color: black;
    • }
    • </style>
    • `
Code
Diff
  • // reescreva em ES6
    function main(a, b = 2, c = 3) {
        
        return a * b * c;
    }
    • // reescreva em ES6
    • function main(a, b, c) {
    • if (typeof b == 'undefined')
    • b = 2;
    • if (typeof c == 'undefined')
    • c = 3
    • function main(a, b = 2, c = 3) {
    • return a * b * c;
    • }