延遲載入

  1. 使用要載入的庫建立 HTML 檔案(在此示例中為 libraries/turf.html):

    <script src="../../bower_components/turf/turf.min.js"></script>
    
  2. 需要時匯入並使用你的庫:

    doSomething: function(argument, anotherArgument): {
    
        // If library has not been loaded, load it
        if(typeof turf == 'undefined') {
            this.importHref(this.resolveUrl('../libraries/turf.js'), function() {
                // Once the library is loaded, recursively call the function
                this.doSomething(argument, anotherArgument);
            }.bind(this));
    
            return;
        }
    
        // Example usage of a library method
        var point = turf.point([42.123123, -23.83839]);
    }