1
此代碼來自recursion的部分。Javascript中的奇怪子句良好的部分
var getElementsByAttribute = function (att, value) {
var results = [];
walk_the_DOM(document.body, function (node) {
var actual = node.nodeType === 1 && node.getAttribute(att);
if (typeof actual === 'string' &&
(actual === value || typeof value !== 'string')) {
results.push(node);
}
});
return results;
};
我不明白下面的子句點:
typeof actual === 'string' && (actual === value || typeof value !== 'string')
它是如何從不同?
typeof actual === 'string' && actual === value
對於'value === 42',第一個條件是成立的哦 – Tibos
Ohhhh,在看了5分鐘之後,我終於意識到兩個_different_變量的'string'性正在被測試'value'和'actual' 。 –
@AlexWayne我應該盯着更長的時間... –