Skip to content

Instantly share code, notes, and snippets.

@brandoncordell
Created February 29, 2012 04:21
Show Gist options
  • Save brandoncordell/1937686 to your computer and use it in GitHub Desktop.
Save brandoncordell/1937686 to your computer and use it in GitHub Desktop.
My javascript-fu
/*
* jQuery - Singleton
*/
var App;
App = {
awesomeLink: null,
ready: function() {
this.awesomeLink = $('#next-link');
this.awesomeLink.bind('click', this.awesomeLinkClicked);
}
awesomeLinkClicked: function(event) {
event.preventDefault();
this.openLightbox();
},
openLightbox: function() {
// do things to open lightbox
}
};
$(document).ready(App.ready);
/*
* jQuery - Singleton in Coffeescript
*/
App =
awesomeLink: null
ready: ->
@awesomeLink = $('#next-link')
@awesomeLink.bind 'click', @awesomeLinkClicked
awesomeLinkClicked: (event) ->
event.preventDefault()
@openLightbox()
openLightbox: ->
// do things to open lightbox
/*
* jQuery - Module Pattern
*/
var App;
App = (function () {
var awesomeLink,
awesomeLinkClicked,
openLightbox;
awesomeLinkClicked = function() {
openLightbox();
};
openLightbox = function() {
// do things to open lightbox
};
return {
ready: function() {
awesomeLink = $('#next-link');
awesomeLink.bind('click', awesomeLinkClicked);
}
};
})();
$(function () {
App.ready();
});
/*
* jQuery - Module pattern in Coffeescript
*/
App = ->
awesome = ->
openLightbox()
openLightbox = ->
// do things to open lightbox
ready: ->
awesomeLink = $('#next-link')
awesomeLink.bind 'click', awesomeLinkClicked
$ ->
App.ready()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment