제이쿼리 callbacks.lock() > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

제이쿼리 callbacks.lock() 정보

jQuery 제이쿼리 callbacks.lock()

본문

제이쿼리 callbacks.lock()

설명 : 현재 상태로 콜백 목록을 잠급니다.


"memory"플래그를 인수로 사용하여 콜백 객체를 만든 경우 콜백 목록이 잠긴 후에 추가 함수가 추가되고 실행될 수 있습니다.

예 :
사용 callbacks.lock()목록 상태로 만들어지고 추가 변경을 방지하기 위해 콜백 목록을 잠글 수 :

// A sample logging function to be added to a callbacks list
var foo = function( value ) {
  console.log( "foo:" + value );
};
 
var callbacks = $.Callbacks();
 
// Add the logging function to the callback list
callbacks.add( foo );
 
// Fire the items on the list, passing an argument
callbacks.fire( "hello" );
// Outputs "foo: hello"
 
// Lock the callbacks list
callbacks.lock();
 
// Try firing the items again
callbacks.fire( "world" );
 
// As the list was locked, no items were called,
// so "world" isn't logged


사용 callbacks.lock()"메모리"를 콜백리스트를 고정하고 목록을 사용하여 다시 시작합니다 :

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>callbacks.lock demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div id="log"></div>
 
<script>
// Simple function for logging results
var log = function( value ) {
  $( "#log" ).append( "<p>" + value + "</p>" );
};
 
// Two sample functions to be added to a callbacks list
var foo = function( value ) {
  log( "foo: " + value );
};
var bar = function( value ) {
  log( "bar: " + value );
};
 
// Create the callbacks object with the "memory" flag
var callbacks = $.Callbacks( "memory" );
 
// Add the foo logging function to the callback list
callbacks.add( foo );
 
// Fire the items on the list, passing an argument
callbacks.fire( "hello" );
// Outputs "foo: hello"
 
// Lock the callbacks list
callbacks.lock();
 
// Try firing the items again
callbacks.fire( "world" );
// As the list was locked, no items were called,
// so "foo: world" isn't logged
 
// Add the foo function to the callback list again
callbacks.add( foo );
 
// Try firing the items again
callbacks.fire( "silentArgument" );
// Outputs "foo: hello" because the argument value was stored in memory
 
// Add the bar function to the callback list
callbacks.add( bar );
 
callbacks.fire( "youHadMeAtHello" );
// Outputs "bar: hello" because the list is still locked,
// and the argument value is still stored in memory
</script>
 
</body>
</html>
추천
0

댓글 0개

전체 5,352
개발자팁 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT