Help me understand this piece of code
Given this piece of code, I don't understand the part I commented:
Code:
function attr(elem, name, value) { // {{{
if (!name || name.constructor != String) return '';
/* I don't understand the [name] = name, and the relation
* of [name] with the previous code in the line. */
name = {'for': 'htmlFor', 'class': 'className'}[name] = name; // I don't understand this line.
if (typeof value != 'undefined') {
elem[name] = value;
if (elem.setAttribute)
elem.setAttribute(attrName, attrValue);
}
return elem[name] || elem.getAttribute(name) || '';
} // }}}
I'll greatelly appreciate any clarification on that. A link with some doc related
to that is equally interesting. Thanks in a advance.