Skip to content

Instantly share code, notes, and snippets.

@prestonp
Created April 1, 2015 17:05
Show Gist options
  • Save prestonp/38a7fc10b550c0de7615 to your computer and use it in GitHub Desktop.
Save prestonp/38a7fc10b550c0de7615 to your computer and use it in GitHub Desktop.
requirejs

AMD asynchronous module definition

Defining a new module

define('Robot', ['jquery'], function($) {
  return function Robot() {
  };
});

Defining a new module, common js style

define(function(require, exports, module)) {
  var jquery = require('jquery');
  
  module.exports = function Robot() {};
}

Using a module

define(['path/to/robot'], function(Robot)) {
  var robot = new Robot();
});

Using a module with common js require

define(function(require, exports, module){
  var Robot = require('path/to/robot');
  var furby = new Robot();
  
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment