当前位置: 首页>>代码示例>>PHP>>正文


PHP js::init方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:hofmeister,项目名称:Pimple,代码行数:54,代码来源:js.php


注:本文中的js::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。