====== $p._callInit() – initialization helper ======
Helper method to call all ''init()'' methods of sub-objects of a passed code object.
- Usage
- $p._callInit(obj, pre)
- Member of:
- [[framework:page:p-core:index|$p]] (core)
- Parameters:
- obj – an object containing sub-objects which in turn contain ''_init()'' and/or ''init()'' functions (required) \\ pre – if true, the ''_init()'' methods will be called, otherwise ''init()'' (optional, default: true)
Notes:
* the called methods will be [[mdn>Web/JavaScript/Reference/Global_Objects/Function/bind|bound]] to their containing object. This means that ''[[mdn>Web/JavaScript/Reference/Operators/this|this]]'' is guaranteed to refer to the object they are in.
* the called functions will have an (optional) parameter that refers to the //parent// object (i.e. to the obj that was passed to this function.
====== Example ======
This is an example of how the console ''init()'' implementation may look like:
$p.console.init = function(parent) {
this.setTarget(document.getElementById('console'));
}
As ''this'' refers to ''$p.console'', it can be used as a shortcut to the ''setTarget()'' method.
In this example, ''parent'' refers to ''$p'', though it could be omitted, as it is not used here.
===== See also =====
* [[framework:page:p-core:index|$p]] (core)