Let\'s say I wanted to create an input element using the DOM. Instead of doing something like this
var input = document.createElement(\"input\");
input.setAt
I personally think you're taking DRY too far (the three statements do different things, so I don't see how it's not DRY.) But if you must abstract it, just write a function to do it:
var input = document.createElement("input");
function setAttributes(el, options) {
Object.keys(options).forEach(function(attr) {
el.setAttribute(attr, options[attr]);
})
}
setAttributes(input, {"class": "my-class", "type": "checkbox", "checked": "checked"});
console.log(input);