php v8js 执行外部js,什么是PHP v8js中的扩展?

原始答案

我的原始答案表明,每次执行executeString时都会调用扩展名.

更正了答案

扩展是在给定V8Js实例的第一个executeString调用之前执行的一些代码.

扩展可以是所有V8J实例的全局扩展,也可以是特定实例的本地扩展.

我已经通过实验确定这并不总是非常可靠.如果你疯狂刷新一个页面,你可能并不总是看到扩展程序运行…这可能是为什么这是beta版软件.

这是我掀起的两个例子

全球扩展示例

V8Js::registerExtension('say_hi', 'print("hey from extension! "); var said_hi=true;', array(), true);

$v8 = new V8Js();

$v8->executeString('print("hello from regular code!")', 'test.php');

$v8->executeString('if (said_hi) { print(" extension already said hi"); }');

产量

hey from extension! hello from regular code! extension already said hi

非全球范例

V8Js::registerExtension('say_hi', 'print("hey from non global extension! "); var said_hi=true;');

$v8 = new V8Js('PHP', array(), array('say_hi'));

$v8->executeString('print("hello from regular code!");', 'test.php');

$v8->executeString('if (said_hi) { print(" extension already said hi"); }');

产量

hey from non global extension! hello from regular code! extension already said hi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值