In past examples, our code has been fairly ad hoc; we've created functions when necessary on a per-project basis. If we could compartmentalize our code, as the Highcharts library does, then we could leverage what we've learned in multiple projects or even share our changes. This recipe will look at how we can create our own library that builds off Highcharts.
To get started, perform the following steps:
Create a new file
myExtension.js
, and, in it, include an immediate function, as shown in the following code:(function(w, H, $) { }(window, Highcharts, jQuery));
Create a new object in the
window
scope, if one does not exist, as shown in the following code:(function(w, H, $) { w.MyExtension = w.MyExtension || {}; }(window, Highcharts, jQuery));
Create a
Chart
function as shown in the following code:(function(w, H, $) { var me; w.MyExtension = w.MyExtension || {}; me = w.MyExtension; me.Chart = me.Chart || Highcharts...