Skip to content

Instantly share code, notes, and snippets.

@brianarn
Forked from padolsey/gist:1463408
Created December 11, 2011 23:22
Show Gist options
  • Save brianarn/1463450 to your computer and use it in GitHub Desktop.
Save brianarn/1463450 to your computer and use it in GitHub Desktop.
`given(d).define(m)` - an alternative to `define(d,m)`
function given(dependencies) {
return {
define: function(id, module) {
if (!module) {
// Assume the first arg is the module
module = id;
id = undefined;
}
return define(id, dependencies, module);
}
};
}
// usage:
given(['foo', 'bar']).define(function(foo, bar){
// Return a value for the module being defined
});
// Normally the ID isn't explicitly set, used by build systems
given(['foo', 'bar']).define('myModule', function(foo, bar){
// Same as above
});
@ryanflorence
Copy link

... meh

After 6 months of heavy use of AMD I've never had an issue using the current define signature, nor have I had any team members struggle with it. Most get it w/o an explanation.

@padolsey
Copy link

@rpflorence, It's not about speed of acquisition for me. It's just about semantics. Programs tell stories. I don't want to open up code everyday of my life and say, "Well, it's understood by everyone. It's not the best thing possible.. but it's good enough" ... It's uninspiring and dull to not want to perfect the APIs we work with everyday.

@ryanflorence
Copy link

I'm saying it already tells the story. Verbally Readable Code !== More Comprehensible Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment