prototype functions throw TypeError when called on non-object value