本文整理汇总了PHP中js::init方法的典型用法代码示例。如果您正苦于以下问题:PHP js::init方法的具体用法?PHP js::init怎么用?PHP js::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js
的用法示例。
在下文中一共展示了js::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: define
/**
* sample use:
*
* define("external",
* array("include"=>"my_js_include", "require"=>"my_js_require"),
* array("PI"=>3.1415926535, "ZERO"=>0) );
*
* A few notes:
* - this function create a new Object() and assign it as $objname on the global object.
* - every function and variable is placed as a direct property of $objname
* - those functions will have a length of 0. I'd be surprised if someone cares.
* - those functions won't have a prototype. Again, not likely to matter much.
* - variables cannot contain arrays or objects. use the real jsrt:: API for that stuff.
*
*/
static function define($objname, $funcarray, $vararray = null)
{
#-- start by covering our basics
js::init();
#-- define the main object
$obj = new js_object();
jsrt::define_variable($objname, $obj);
#-- start linking our functions
jsrt::push_context($obj);
foreach ($funcarray as $js => $php) {
jsrt::define_function($php, $js);
}
jsrt::pop_context();
#-- put variables in place
foreach ((array) $vararray as $js => $php) {
#-- odd, but php.net discourages the use of gettype, so watch me comply.
switch (true) {
case is_bool($php):
$v = new js_val(js_val::BOOLEAN, $php);
break;
case is_string($php):
$v = js_str($php);
break;
case is_numeric($php):
$v = js_int($php);
break;
case is_null($php):
$v = jsrt::$null;
break;
case is_array($php):
/* we could do something smarter here. maybe later. */
/* we could do something smarter here. maybe later. */
default:
$v = jsrt::$undefined;
break;
}
$obj->put($js, $v);
}
}