In computer programming, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time. The invocation may be immediate as in a synchronous callback or it might happen at later time, as in an asynchronous callback.
def onclick():
print 'Button clicked!'
# call the onclick() method when the 'click' event happens on the button
some_api.register_callback(button, 'click', onclick)
通常,这意味着您要创建一个函数:
然后将该函数传递给提供的API中的某个类:
^{pr2}$现在,
API_class_instance
将在文档环境下调用foo
。在Callback:
因此,如果您正在注册一个uiapi回调,那么您可能会将您创建的某个函数传递给另一个函数,该函数将负责在某些情况发生时调用您的函数。在
例如,您可能在UI中有一个按钮,并且您希望在单击该按钮时执行一些代码。您可以注册如下所示的回调:
API代码可能如下所示:
^{pr2}$相关问题 更多 >
编程相关推荐