A few JavaScript ideas stolen from AngularJS source