This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Event Pooling, or perhaps Pub/Sub</title> | |
<script type="text/javascript" charset="utf-8" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script> | |
</head> | |
<body> | |
<strong>Who is this?</strong> | |
<form action="#" method="get" accept-charset="utf-8" id="whoisit"> |
This file contains 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
var element = $("div.form-errors"); | |
if (formHasErrors()) { | |
element.show(); | |
} | |
// More, unrelated code... | |
var element = $("form#login"); | |
element.addClass("has-errors"); |
This file contains 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
var LoginFom = { | |
element: $("form#login-form"), | |
hasErrors: function() { | |
// validation code here... | |
// returns true or false. | |
} | |
}; | |
// ... |
This file contains 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
// Old | |
function sum($elements) { /* calculate sum */ } | |
function product($elements) { /* calculate sum */} | |
// New | |
var MathUtils = { | |
function sum($elements) {}, | |
function product($elements) {} | |
}; |
This file contains 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
// Old | |
var DEBUG = false; | |
var MAX_ENTRIES = 100; | |
var FEED_URL = "http://mysite.com/feed/"; | |
var POST_IDS = [123, 456, 789]; | |
// New | |
var Config = { | |
DEBUG: true, | |
MAX_ENTRIES: 100, |
This file contains 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
// Heavily Coupled | |
$(function() { | |
$(document.body).append( $('<select id="countries"></select>') ); | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' |
This file contains 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
// Less Coupled | |
var CountrySelectClass = function() { | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' | |
}; |
This file contains 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
var MyNamespace = { | |
myString: "someString", | |
myInt: 123, | |
myFunc: function() { | |
return this.myString + " " + this.myInt; | |
} | |
}; |
This file contains 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
MyNamespace.myString; | |
MyNamespace.myInt; | |
MyNamespace.myFunc(); |
This file contains 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
var MyCompany = { | |
Widgets: { | |
data1: 123, | |
func1: function() {} | |
}, | |
HtmlUtils: { | |
data1: 123, | |
func1: function() {} | |
} | |
} |
OlderNewer