Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion has.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@
// Expose has()
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
if(typeof define == "function" && typeof define.amd == "object" && define.amd){
define("has", function(){
define("has", ["module"], function(module){
var moduleConfig = {};
if(typeof module.config == "function"){
moduleConfig = module.config() || {};
}
for (var propKey in moduleConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undefined values in a for-in should not error,e.g. for(var foo in undefined){ so no need for all the object guards.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moduleConfig can't be undefined because if somehow module.config() returns value that is null or undefined then {} will be assigned to moduleConfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code style seems to favor hoisting vars out (it was a phase :P). So that would make it:

var propKey, moduleConfig;
if(typeof module.config == "function"){
  moduleConfig = module.config();
}
for(propKey in moduleConfig){

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just use simple code for this as @jrburke has done in https://github.com/requirejs/text/blob/master/text.js#L23

var moduleConfig = (module.config && module.config()) || {};
for(var propKey in moduleConfig){
    has.add(propKey, moduleConfig[propKey]);
}

something like that above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naw, different project styles. We are consuming a foreign thing so have to be more cautious whereas that plugin expects to work with RequireJS and its constructs.

has.add(propKey, moduleConfig[propKey]);
return has;
});
}
Expand Down