나는 다음이있다 object
function AnimatedObject(object)
{
this.object = object;
/*
Functions
*/
this.fadeOutAnimation = fadeOutAnimation;
this.objectToggle = objectToggle;
this.objectClick = objectClick;
}
function fadeOutAnimation()
{
this.object.animate({
opacity: 0.25,
left: "+=150",
height: "toggle"
}, 2500, function() {
this.objectToggle();
});
}
function objectToggle()
{
this.object.toggle();
}
내 animate
함수 내부에서 나는 호출된다.this.objectToggle();
그러나 애니메이션이 완료되면 undefined is not a function
나는 그것에 대한 참조가없는 내부 콜백 함수 때문이라는 것을 꽤 certian입니다. object
내 질문은 내 개체에 대한 참조를 제공하여 콜백 함수 내부에서 해당 함수를 호출 할 수 있도록하는 방법입니다.
함수를 올바른 컨텍스트에 바인딩하십시오.
function fadeOutAnimation()
{
this.object.animate({
opacity: 0.25,
left: "+=150",
height: "toggle"
}, 2500, function() {
this.objectToggle();
}.bind(this));
}
또는 다음에 대한 참조를 저장하십시오 this
.
function fadeOutAnimation()
{
var that = this;
this.object.animate({
opacity: 0.25,
left: "+=150",
height: "toggle"
}, 2500, function() {
that.objectToggle();
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다