다음과 같은 생성자 개체가 있습니다. 메신저 "fcClick는"은 "이"는 바인더 제본 HTML 요소를 참조하는 bind 함수가 아닌로 실행될 때js에서 event로 함수 bind 내에서 객체 참조를 가져옵니다.?
var Cons = function(me){
this.name= me;
this.ele = document.getElementById("element");
this.ele.addEventListener("click",this.fnClick,false);
}
어떤 방법이 프로토 타입으로 확장이
Cons.prototype.getme= function(){
return this.me;
}
Cons.prototype.fnClick= function(){
alert(this.getme())
}
var initZ = new Cons("test");
그래서 내 문제는 현재 인스턴스 Object
그래서 "this"의 참조를 "fnClick"..에 전달할 수 있습니까?
YS가 actualy 내가 자기 참조와 마찬가지로 원하는 (
getme()
이this.name
를 반환과) http://jsfiddle.net/Fy5ZV/1/를 참조하십시오,하지만 난이 결합 기운을 다만 공공 기능을 내가 다른 기능에 removeEvent을해야하고, 내가 선언 질수 있기 때문에 개인 FN 핸들러는 프레임 워크의 그 부분은 .. – Sarath당신은 여기 [참조 Function.prototype.bind''에 대한 심의를 구현할 수 있습니다 ] (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obj ects/Function/bind), * Compatibility * 섹션. –