How to write a define wrapper around the require js function

151 views Asked by At

I want to wrap the following code as a define method

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

I use durandal SPA . so i need to have a define method to cal it from other places .

1

There are 1 answers

0
Damian Dziaduch On BEST ANSWER

The simplest solution is to replace require with define:

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