UNPKG

@moomfe/zenjs

Version:

ZenJS 是一个高性能的 JavaScript 工具库。

22 lines (17 loc) 780 B
import "../../../shared/polyfill/Element.prototype.matches"; import inBrowser from "../../../shared/const/inBrowser"; import defineValue from "../../../shared/util/defineValue"; import ElementProto from "../../../shared/global/DomElement/prototype/index"; import isString from "../../../shared/util/isString"; import isFunction from "../../../shared/util/isFunction"; if( inBrowser ){ defineValue( ElementProto, '$is', function( selector ){ if( selector.nodeType ) return this === selector; else if( isString( selector ) ) return this.matches( selector ) else if( isFunction( selector ) ) return !!selector( this ); return false; }); defineValue( ElementProto, '$not', function( selector ){ return !this.$is( selector ); }); }