function T(x){ return (x.textContent) ? function(y){ x.textContent = y; } : function(y){ x.innerText = y; }; }
T(nodeA)('string');
nodeText = T(nodeB);
nodeText('string');
If I change (x.textContent) to (x.textContent !== undefined) it works in firefox. Otherwise I get no errors but nothing happens. Inspecting with firebug shows that T(node); returns function(), which is just baffling to me.
I’m new to javascript but I’m thinking this could be a bug?? I think it can only be true or false, it should be true and return first function but it doesn’t return either. Can someone say why?
This won’t work if the
textContentfor the given node is an empty string'', which evaluates tofalse. That’s why you should do(typeof x.textContent !== 'undefined')instead to ensure the existence of the property.