jQuery 객체가 있고 그 객체에 이벤트를 할당하기 위해 .bind()
메서드를 사용하고 있습니다. 그러나 나는 또한과 같이뿐만 아니라 바인드 방법으로 개체 자체에 대한 참조를 전달 해요 :사용중인 바로 객체에 대한 참조를 전달하면 순환 참조가 발생합니다.
$(document).ready(function()
{
// Grab the jQuery version of the DOM element.
var $formField1 = $("#form-field-1");
// I should probably store this stuff in $formField1.data(),
// but not until I find out if this can cause a circular reference.
var formFields = {
"jQ": $formField1,
"$comment": $("#form-field-1-comment"),
"commentAnswers": [ 2, 4 ]
};
// Set up the comment to show when a certain answer is given.
this.jQ.bind("change", formFields, toggleComment);
});
function toggleComment(p_event)
{
// Show/hide comments based on the answer in the commentAnswers array.
if ($.inArray($(this).val(), question.commentAnswers) > -1)
{
question.$comment.parent().slideDown();
}
else
{
question.$comment.parent().slideUp();
}
}
나는이 "사실"순환 참조가 발생할 수 있는지 알고 싶어?
'this.jQ'란 무엇입니까? 'formFields.jQ'라는 뜻이 아닌가요? 어떤 경우에는'$ formField1'을 사용하십시오. –
원래 코드에는 양식의 모든 양식 필드에서 $ .each 루프가 수행됩니다. 관련성이없는 코드를 제외하고 싶었고이 코드를 $ formField1로 변경하지 못했습니다. – b01