Skip to content

Commit d4a92e4

Browse files
committed
Pass options obj instead of multiple arguments
1 parent da54b3b commit d4a92e4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

objgrep.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,18 @@
6262

6363
Object.defineProperty(Object.prototype, 'grep', {
6464
enumerable: false,
65-
value: function (regex, depth, allow_dom, context) {
66-
if (typeof depth !== "number") {
67-
depth = 5;
68-
console.log('Using a default search depth of ' + depth);
65+
value: function (regex, opts) {
66+
var defaults = {
67+
depth: 5,
68+
allow_dom: true
69+
}, options = {}, opt;
70+
for (opt in ['depth', 'allow_dom', 'context']) {
71+
options[opt] = opts[opt] || defaults[opt];
6972
}
70-
if (typeof allow_dom === 'undefined') {
71-
allow_dom = true;
73+
if (typeof opts.depth !== "number") {
74+
console.log('Using a default search depth of ' + options.depth);
7275
}
73-
return objgrep(this, regex, depth, allow_dom, context);
76+
return objgrep(this, regex, options.depth, options.allow_dom, options.context);
7477
}
7578
});
7679
})();

0 commit comments

Comments
 (0)