수

제이쿼리 callbacks.lock()

· 2017-08-16 (수) 19:06:28 · 2053
제이쿼리 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>
|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

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

+
분류 제목 글쓴이 날짜 조회
jQuery 18-01-25 조회 4,584
JavaScript 18-01-24 조회 8,622
기타 18-01-24 조회 2,892
웹서버 18-01-24 조회 3,118
기타 18-01-22 조회 7,949
기타 18-01-22 조회 5,851
웹서버 18-01-18 조회 6,963
PHP 18-01-12 조회 6,457
jQuery 18-01-10 조회 3,985
jQuery 18-01-10 조회 2,855
jQuery 18-01-10 조회 3,495
MySQL 18-01-08 조회 3,676
jQuery 18-01-08 조회 2,994
jQuery 18-01-08 조회 3,211
jQuery 18-01-08 조회 4,924
PHP 18-01-05 조회 4,868
jQuery 18-01-04 조회 4,665
jQuery 18-01-04 조회 3,291
jQuery 18-01-04 조회 2,748
jQuery 17-12-06 조회 2,931
jQuery 17-12-06 조회 3,695
jQuery 17-12-06 조회 3,520
jQuery 17-12-04 조회 2,908
jQuery 17-12-04 조회 2,145
jQuery 17-12-04 조회 3,099
jQuery 17-12-04 조회 2,968
jQuery 17-11-25 조회 2,772
jQuery 17-11-25 조회 2,728
jQuery 17-11-25 조회 2,389
jQuery 17-11-24 조회 2,479