Search code examples
highchartsrequirejsdurandal

How to write a define wrapper around the require js function


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 .


Solution

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