我有一个 jQuery 对象,我正在使用.bind()
方法将事件分配给该对象。但是,我还将对对象本身的引用传递给 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();
}
}
我想知道这是否会“事实上”导致循环引用?