Skip to content

Commit 3417371

Browse files
committed
refactor(DateObject): Remove for loop in favor of .filter() and .forEach()
Constructor now iteraates over first argument keys, filters out invalid keys, and sets properties on the DateObject. Previous implemntation requried adding ignore comments for uncovered code. The new code has few branches and cannot inherite properties from the constructor objects parent(s)
1 parent 8923802 commit 3417371

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/js/datetimepicker.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,13 @@
415415

416416
var validProperties = ['utcDateValue', 'localDateValue', 'display', 'active', 'selectable', 'past', 'future']
417417

418-
for (var prop in arguments[0]) {
419-
/* istanbul ignore else */
420-
// noinspection JSUnfilteredForInLoop
421-
if (validProperties.indexOf(prop) >= 0) {
422-
// noinspection JSUnfilteredForInLoop
423-
this[prop] = arguments[0][prop]
424-
}
425-
}
418+
var constructorObject = arguments[0]
419+
420+
Object.keys(constructorObject).filter(function (key) {
421+
return validProperties.indexOf(key) >= 0
422+
}).forEach(function (key) {
423+
this[key] = constructorObject[key]
424+
}, this)
426425
}
427426

428427
return directiveDefinition

0 commit comments

Comments
 (0)