Skip to content

Instantly share code, notes, and snippets.

View elplatt's full-sized avatar

Edward L Platt elplatt

View GitHub Profile
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<button id="button">Click me!</button>
<div id="new-color"></div>
<div id="all-colors"></div>
</body>
@elplatt
elplatt / dict-example.js
Created August 28, 2013 17:48
This JavaScript class wraps an Object to provide useful hash table / dictionary functionality. All data is maintained in the underlying Object. It doesn't pollute Object.prototype, so it plays nice with jQuery. See dict-example.js for examples.
map = {
"USA": { "Detroit": 23, "Cambridge": 5, "Cupertino": 0.5 },
"Canada": { "Waterloo": 1 },
"Switzerland": { "Geneva": 0.5 }
}
d = new Dict(map);
d.getDict("USA").get("Detroit"); // => 23
d.getDict("China", {}).get("Beijing", 0); // => 0
@elplatt
elplatt / lineage-example.js
Last active August 29, 2015 13:58
Alternative to global namespacing. Rather than having globals or Singletons, declare each object you want to access to as a "lineage". The spawn() function is used to pass lineage values from an instance of class Elder to a new instance of class Younger: youngerInstance = elderInstance.spawn(Younger).
Pet = Model.extend({})
PetController = Controller.extend({
"initialize": function (options) {
this.names = options.names;
this.model = this.spawn(Pet)
this.view = this.spawn(PetView, {
"model": this.model
}) // "names" is passed implicitly
this.view.render();