1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        esnextES6 轉(zhuǎn) JavaScript

        聯(lián)合創(chuàng)作 · 2023-09-22 09:17

        esnext 是一個 JavaScript 庫,可以將 ES6 草案規(guī)范語法轉(zhuǎn)成今天的 JavaScript 語法。

        例如:

        /*
        On the left is code written with new JavaScript features,
        and on the right is the console output, plus the same code
        re-written so it can run in today's browsers.
        
        Edits made to the code on the left will re-generate and
        re-run the code on the right. Try it out!
        */
        
        // Classes
        class Person {
          constructor(firstName, lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
          }
        
          get name() {
            // Template strings
            return `${this.firstName} ${this.lastName}`;
          }
        
          toString() {
            return this.name;
          }
        }
        
        console.log(
          'Full name is:',
          new Person('Michael', 'Bluth')
        );
        
        // Arrow functions
        console.log([1, 2, 3].map(x => x * x));
        
        // Rest params
        function join(delim, ...items) {
          return items.join(delim);
        }
        
        // Spread args
        console.log(join('-', ...[415, 555, 1212]));

        將被轉(zhuǎn)換成:

        /*
        On the left is code written with new JavaScript features,
        and on the right is the console output, plus the same code
        re-written so it can run in today's browsers.
        
        Edits made to the code on the left will re-generate and
        re-run the code on the right. Try it out!
        */
        
        // Classes
        var $__Array$prototype$slice = Array.prototype.slice;
        var $__Object$defineProperties = Object.defineProperties;
        
        var Person = function() {
          "use strict";
        
          function Person(firstName, lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
          }
        
          $__Object$defineProperties(Person.prototype, {
            name: {
              get: function() {
                // Template strings
                return "" + this.firstName + " " + this.lastName + "";
              },
        
              enumerable: true,
              configurable: true
            },
        
            toString: {
              value: function() {
                return this.name;
              },
        
              enumerable: false,
              writable: true
            }
          });
        
          $__Object$defineProperties(Person, {});
          return Person;
        }();
        
        console.log(
          'Full name is:',
          new Person('Michael', 'Bluth')
        );
        
        // Arrow functions
        console.log([1, 2, 3].map(function(x) {
          return x * x;
        }));
        
        // Rest params
        function join(delim) {
          var $__arguments = arguments;
          var items = [].slice.call($__arguments, 1);
          return items.join(delim);
        }
        
        // Spread args
        console.log(join.apply(null, ['-'].concat($__Array$prototype$slice.call([415, 555, 1212]))));

        使用方法:

        var transpiler = require('es6-module-transpiler');
        var Container = transpiler.Container;
        var FileResolver = transpiler.FileResolver;
        var BundleFormatter = transpiler.formatters.bundle;
        
        var container = new Container({
          resolvers: [new FileResolver(['lib/'])],
          formatter: new BundleFormatter()
        });
        
        container.getModule('index');
        container.write('out/mylib.js');
        瀏覽 17
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            欧美肏逼| 性爱久久 | 黃色毛片A片AAAA级 2 0 | 慈禧一级淫片免费放特级 | 亚洲国产成人视频 | 国产精品豆花麻豆 | 亚洲高清永久 | 美女被桶秘 免费网站 | 熟交xxxxⅹ欧美老妇妇性蜜桃 | 五月天激情久久 |