Object oriented library implementation in javascript