제이쿼리 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
댓글 0개