Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate example to es6 #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific k
or install `mousetrap` from `npm` and require it

```js
var Mousetrap = require('mousetrap');
const Mousetrap = require('mousetrap');
```

2. Add some keyboard events to listen for

```html
<script>
// single keys
Mousetrap.bind('4', function() { console.log('4'); });
Mousetrap.bind("?", function() { console.log('show shortcuts!'); });
Mousetrap.bind('esc', function() { console.log('escape'); }, 'keyup');
Mousetrap.bind('4', () => { console.log('4'); });
Mousetrap.bind("?", () => { console.log('show shortcuts!'); });
Mousetrap.bind('esc', () => { console.log('escape'); }, 'keyup');

// combinations
Mousetrap.bind('command+shift+k', function() { console.log('command shift k'); });
Mousetrap.bind('command+shift+k', () => { console.log('command shift k'); });

// map multiple combinations to the same callback
Mousetrap.bind(['command+k', 'ctrl+k'], function() {
Mousetrap.bind(['command+k', 'ctrl+k'], () => {
console.log('command k or control k');

// return false to prevent default browser behavior
Expand All @@ -50,11 +50,11 @@ It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific k
});

// gmail style sequences
Mousetrap.bind('g i', function() { console.log('go to inbox'); });
Mousetrap.bind('* a', function() { console.log('select all'); });
Mousetrap.bind('g i', () => { console.log('go to inbox'); });
Mousetrap.bind('* a', () => { console.log('select all'); });

// konami code!
Mousetrap.bind('up up down down left right left right b a enter', function() {
Mousetrap.bind('up up down down left right left right b a enter', () => {
console.log('konami code');
});
</script>
Expand Down