you define it using the AMD pattern:
$.fn.select2.amd.define('select2/data/customAdapter',[ 'select2/data/array', 'select2/utils' ], function (ArrayAdapter, Utils) { function CustomDataAdapter ($element, options) { CustomDataAdapter.__super__.constructor.call(this, $element, options); } Utils.Extend(CustomDataAdapter, ArrayAdapter); CustomDataAdapter.prototype.current = function (callback) { callback(...); }; return CustomDataAdapter; } ); var customAdapter=$.fn.select2.amd.require('select2/data/customAdapter'); $("#my").select2({ tags: true, dataAdapter: customAdapter });
source share