Defining an AMD module in JavaScript
Testing out the protip feature
Here's how I define a RequireJS/NodeJS compliant module:
Verbose
define('ninja', function(require, exports, module) {
var Class = require('./class-util');
var Ninja = {
teleport: function() {},
shuriken: function() {}
katana: function() {}
};
return module.exports = Class.extend(Ninja);
});
Minimal
define('ninja', function(require, exports, module) {
var Class = require('./class-util');
return module.exports = Class.extend({
teleport: function() {},
shuriken: function() {}
katana: function() {}
});
});
More minimal
define('ninja', function(require, exports, module) {
return module.exports = require('./class-util').extend({
teleport: function() {},
shuriken: function() {}
katana: function() {}
});
});Written by James Florentino
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Amd
Authors
gerardsans
12.4K
cgarvis
7.298K
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#