User:Mike Dillon/Scripts/easydom.js: Difference between revisions

Content deleted Content added
m first argument of "call()" becomes "this", so pass elem as second arg
m break out single attribute handling into a function
Line 9:
var elem = document.createElement(name);
return elem;
};
 
var processSingleDomAttribute = function(elem, attrName, attrValue) {
// Invoke function callbacks and use their result as the value
if (typeof attrValue == functionType) {
// Pass null for "this"
attrValue = attrValue.call(null, elem);
}
 
// Skip null values
if (attrValue == null) {
}return;
}
 
// Set the attribute
elem.setAttribute(attrName, attrValue);
};
 
Line 40 ⟶ 56:
var attrs = args[0];
for (var attrName in attrs) {
varprocessSingleDomAttribute(elem, attrValue =attrName, attrs[attrName]);
// Invoke function callbacks and use their result as the value
if (typeof attrValue == functionType) {
// Pass null for "this"
attrValue = attrValue.call(null, elem);
}
// Skip null values
if (attrValue == null) {
continue;
}
// Set the attribute
elem.setAttribute(attrName, attrValue);
}