- 广为流传版本 的 new + 提供非扫码情况下的数据返回
function ScannerListener(resolve, event, reject) {
this.event = event || document
this.resolve = resolve
this.reject = reject
this.code = ""
this.rejcetCode = ""
this.lastTime = undefined
this.nextTime = undefined
this.lastCode = undefined
this.nextTime = undefined
}
ScannerListener.prototype.init = function (resolve, reject){
if(!this.event){
throw Error('没有事件绑定元素')
}
this.event.onkeypress = (e) => {
this.nextCode = e.keyCode
if (this.nextCode === 13) {
console.log(this, 'keypress')
if (this.code.length < 3) {
this.reject && this.reject(this.rejcetCode)
reject && reject