I don't think this needs to be a function.  Instead, you should just be running the bidi algorithm on things and putting the result directly on `this.direction`, as in `this.direction = "ltr";`