Writing a framework in JavaScript