an implementation of ruby's method resolution order in javascript