Last active
January 29, 2021 10:25
-
-
Save s749312025/323828043b12b313a1edbfb431b59cf9 to your computer and use it in GitHub Desktop.
页面彩蛋
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function egg(arr, callback) { | |
this.sequence = arr.join(',') | |
this.length = arr.length | |
this.pressed = [] | |
this.callback = callback | |
this.init() | |
} | |
egg.prototype = { | |
constructor: egg, | |
init: function () { | |
document.addEventListener('keyup', this.handleKey.bind(this), false) | |
}, | |
handleKey: function (e) { | |
this.pressed.push(e.keyCode) | |
console.log(this.pressed) | |
this.check() | |
}, | |
check: function () { | |
if (this.pressed.join(',') == this.sequence) { | |
this.callback() | |
this.pressed = [] | |
} else if (this.pressed.length == this.length) { | |
this.pressed.shift() | |
} | |
}, | |
} | |
new egg([38, 40, 38, 40], function () { | |
alert('go!') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment