{"name":"callbacks.lock","type":"method","title":"callbacks.lock()","deprecated":null,"removed":null,"desc":"Lock a callback list in its current state.","categories":["callbacks-object","version/1.7"],"entries":[{"return":"Callbacks","signatures":{"added":"1.7"},"examples":[{"desc":"Use callbacks.lock() to lock a callback list to avoid further changes being made to the list state:","code":"\n// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo:\" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Lock the callbacks list\ncallbacks.lock();\n\n// Try firing the items again\ncallbacks.fire( \"world\" );\n\n// As the list was locked, no items were called,\n// so \"world\" isn't logged\n"},{"desc":"Use callbacks.lock() to lock a callback list with \"memory,\" and then resume using the list:","html":"\n
\n","code":"\n// Simple function for logging results\nvar log = function( value ) {\n $( \"#log\" ).append( \"

\" + value + \"

\" );\n};\n\n// Two sample functions to be added to a callbacks list\nvar foo = function( value ) {\n log( \"foo: \" + value );\n};\nvar bar = function( value ) {\n log( \"bar: \" + value );\n};\n\n// Create the callbacks object with the \"memory\" flag\nvar callbacks = $.Callbacks( \"memory\" );\n\n// Add the foo logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Lock the callbacks list\ncallbacks.lock();\n\n// Try firing the items again\ncallbacks.fire( \"world\" );\n// As the list was locked, no items were called,\n// so \"foo: world\" isn't logged\n\n// Add the foo function to the callback list again\ncallbacks.add( foo );\n\n// Try firing the items again\ncallbacks.fire( \"silentArgument\" );\n// Outputs \"foo: hello\" because the argument value was stored in memory\n\n// Add the bar function to the callback list\ncallbacks.add( bar );\n\ncallbacks.fire( \"youHadMeAtHello\" );\n// Outputs \"bar: hello\" because the list is still locked,\n// and the argument value is still stored in memory\n"}],"longdesc":"\n

This method returns the Callbacks object onto which it is attached (this).

\n

If the Callbacks object is created with the \"memory\" flag as its argument, additional functions may be added and fired after the callback list is locked.

\n "}]}