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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#