Snippets Collections
// Define your class
class MyModule {
  constructor($) {
    this.$ = $;
  }
  
  // Add methods and properties here
}

// Environment detection and initialization
(function() {
  if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
    // CommonJS
    module.exports = MyModule;
  } else if (typeof define === 'function' && define.amd) {
    // AMD
    define(['jquery'], function($) {
      return new MyModule($);
    });
  } else {
    // Global
    if (typeof window.jQuery !== 'undefined') {
      window.MyModule = MyModule;
    }
  }
})();
star

Thu Oct 19 2023 06:05:24 GMT+0000 (Coordinated Universal Time)

#javascript #amd #commonjs #module

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension