MCPcopy Create free account
hub / github.com/JsAaron/jQuery / assert

Function assert

2.0.3/Sizzle-annotation.js:364–390  ·  view source on GitHub ↗

* Support testing using an element * 用于做各种特征检测,比如是否支持某个API,API支持是否完美 * @param {Function} fn Passed the created div and expects a boolean result

(fn)

Source from the content-addressed store, hash-verified

362 */
363
364 function assert(fn) {
365 var div = document.createElement("div");
366
367 try {
368 /**
369 * !!一般用来将后面的表达式强制转换为布尔类型的数据(boolean),也就是只能是true或者false;
370 * var o={flag:true};
371 var test=!!o.flag;//等效于var test=o.flag||false;
372 由于对null与undefined用!操作符时都会产生true的结果,
373 所以用两个感叹号的作用就在于,
374 如果明确设置了o中flag的值(非null/undefined/0""/等值),
375 自然test就会取跟o.flag一样的值;
376 如果没有设置,test就会默认为false,而不是null或undefined。
377 alert(test);
378 */
379 return !!fn(div);
380 } catch (e) {
381 return false;
382 } finally {
383 // Remove from its parent by default
384 if (div.parentNode) {
385 div.parentNode.removeChild(div);
386 }
387 // release memory in IE
388 div = null;
389 }
390 }
391
392 /**
393 * Adds the same handler for all of the specified attrs

Callers 1

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected