제이쿼리 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>
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4736 | jQuery | 8년 전 | 1562 | ||
| 4735 | jQuery | 8년 전 | 1753 | ||
| 4734 | jQuery | 8년 전 | 1741 | ||
| 4733 | jQuery | 8년 전 | 2036 | ||
| 4732 | jQuery | 8년 전 | 1959 | ||
| 4731 | jQuery | 8년 전 | 1461 | ||
| 4730 | jQuery | 8년 전 | 1919 | ||
| 4729 | PHP |
|
8년 전 | 6906 | |
| 4728 | jQuery | 8년 전 | 2563 | ||
| 4727 | jQuery | 8년 전 | 1612 | ||
| 4726 | jQuery | 8년 전 | 1692 | ||
| 4725 | jQuery | 8년 전 | 1835 | ||
| 4724 | jQuery | 8년 전 | 1313 | ||
| 4723 | jQuery | 8년 전 | 1865 | ||
| 4722 | jQuery | 8년 전 | 1630 | ||
| 4721 | jQuery | 8년 전 | 1919 | ||
| 4720 | jQuery | 8년 전 | 1981 | ||
| 4719 | jQuery | 8년 전 | 1603 | ||
| 4718 | jQuery | 8년 전 | 1609 | ||
| 4717 | jQuery | 8년 전 | 1561 | ||
| 4716 | jQuery | 8년 전 | 1240 | ||
| 4715 | jQuery | 8년 전 | 1397 | ||
| 4714 | jQuery | 8년 전 | 1419 | ||
| 4713 | jQuery | 8년 전 | 1339 | ||
| 4712 | jQuery | 8년 전 | 2230 | ||
| 4711 | jQuery | 8년 전 | 1717 | ||
| 4710 | PHP |
|
8년 전 | 3748 | |
| 4709 | jQuery | 8년 전 | 1630 | ||
| 4708 | jQuery | 8년 전 | 1912 | ||
| 4707 | jQuery | 8년 전 | 1768 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기