如何围绕 require js 函数编写定义包装器

How to write a define wrapper around the require js function

我想将以下代码包装为定义方法

        require([
            'highcharts',
            'highcharts/modules/exporting',
            'highcharts/modules/accessibility'
        ], function (Highcharts) {
            // This function runs when the above files have been loaded.

            // Create a test chart.
            Highcharts.chart('container', {
                series: [{
                    data: [1,2,3,4,5]
                }]
            });
        });

我使用 durandal SPA。所以我需要一个定义方法来从其他地方调用它。

最简单的解决方案是将 require 替换为 define:

        define([
            'highcharts',
            'highcharts/modules/exporting',
            'highcharts/modules/accessibility'
        ], function (Highcharts) {
            Highcharts.chart('container', {
                series: [{
                    data: [1,2,3,4,5]
                }]
            });
        });