2014-10-05 2 views
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)); 

자바 스크립트에서 올바른 방법인가요? 아니면 내가 (타사 라이브러리 인) this.listener.simple_combo 당신은 지금이자바 스크립트에서 매개 변수로 메서드를 전달하는 관용적 인 방법

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

같은 컬렉션 개체를 바인딩 할 수 있습니다 호출자가이

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

답변

1

같은 메소드 인수를 추가 할 수 있도록 변경해야 this은 올바른 컬렉션 개체를 참조합니다.

관련 문제