Skip to content
tobiasz.cudnik edited this page Oct 2, 2008 · 22 revisions

Table of Contents

Table of Conents

 * [#What_are_callbacks What are callbacks]
 * [#Java_Script_callbacks JavaScript callbacks]
 * [#PHP_callbacks PHP callbacks]
 * [#Param_Structures ParamStructures]
 * [#Supported_Methods Supported Methods]
 * [#Scope_Pseudo_Inheritance Scope Pseudo-Inheritance]

What are callbacks

Callbacks are functions _called back_ by other functions in proper moment (eg on Ajax request error).

Java Script callbacks

In JavaScript this pattern can be very flexible due to Closures support, which can be inline (no code break) and inherits scope (no need to passing params).

PHP callbacks

PHP has only simple support for callbacks so the case is more complicated. That's why [#Param_Structures] has been introduced in phpQuery.

Param Structures

Param Structures are lists of params. Such list can contain values defined by programmer or special places (CallbackParam objects) where function triggering callback will fill it's own values.

Example 1

Example above shows how to easily pass custom params to callback using [#Param_Structures].

Supported Methods

 * `phpQuery::each()`
 * `phpQuery::map()`
 * `pq()->each()`
 * `pq()->map()`

Scope Pseudo Inheritance

There is easy way to pseudo-inherit scope in PHP. Scope means _variables accessible in specified point of code_. It's achieved using compact() and extract() functions.

Example 2

Look at this modified [#Example_1]. Previous comments were removed.

In the future this functionality will be developed and more methods will support it.

Clone this wiki locally