1
// This didn't work because "this" in display_previous_room was Window instead of a Collection object.
this.listener.simple_combo("left",this.collection.display_previous_room);

// This worked
this.listener.simple_combo("right",this.collection.display_next_room.bind(this.collection));

Is this the right way to do it in javascript ? Or should I change this.listener.simple_combo (which is a third party library) to allow the caller to add method arguments like this

this.listener.simple_combo("right",this.collection.display_next_room,this.collection,{...}); // simple_combo(key,function/method,binding,arguments to the function/method)

1 Answer 1

1

You can bind the Collection object like this

this.listener.simple_combo("right", this.collection.display_next_room.bind(this.collection));

so that the this will refer the proper collection object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.