var aQuery = function(selector){ //强制为对象 if(!(this instanceof aQuery)){ return new aQuery(selector) } var elem = document.getElementById(/[^#].*/.exec(selector)[0]); this.length = 1; this[0] = elem; this.context = document; this.selector = selector; this.get = function(num){ return this[num]; } return this }
既可通过aQuery("#book")[0] / aQuery("#book").get(0) 获取到元素