js: refactored inheritance again.

This time going for the functional inheritance model.