Skip to content

Instantly share code, notes, and snippets.

@Wolfr
Created November 3, 2011 20:30
Show Gist options
  • Save Wolfr/1337697 to your computer and use it in GitHub Desktop.
Save Wolfr/1337697 to your computer and use it in GitHub Desktop.
jwerty.key('←', function () {
// Check if we are on the first slide, if so, do not execute
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
};
});
$('#prevSlide').click(function() {
// Check if we are on the first slide, if so, do not execute
if (!$('.introSlide').is(":visible")) {
prevSlide();
buttonToggle();
};
});
@Wolfr
Copy link
Author

Wolfr commented Nov 3, 2011

So we can remove the anonymous functions say eising

Example:

jwerty.key('↑', function () {
  resetSlides();
});

$('.resetSlides').click(function() {
  resetSlides();
});

How?

(NM you were faster :))

@mathiasbynens
Copy link

jwerty.key('↑', function () {
  resetSlides();
});

$('.resetSlides').click(function() {
  resetSlides();
});

Could be just…

jwerty.key('↑', resetSlides);

$('.resetSlides').click(resetSlides);

But actually you don’t need a named function at all:

var $resetSlides = $('.resetSlides');

$resetSlides.click(function() {
  // teh coads
});

jwerty.key('↑', $resetSlides.click); // i.e. just trigger a `click` event on `$resetSlides`

@Wolfr
Copy link
Author

Wolfr commented Nov 3, 2011

Hmm yeah, that makes sense. Your 2nd code block is more readable and I can keep all my functions apart so went for that. The 3rd code block is more 1337 I guess ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment