延迟加载

  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]);
    }