为PhantomJS绑定polyfill [英] bind polyfill for PhantomJS

查看:149
本文介绍了为PhantomJS绑定polyfill的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用es5-shim.js在我的phantomjs文件中添加绑定polyfill.

I am trying to add bind polyfill in my phantomjs file using es5-shim.js.

我尝试使用require()包含es5-shim.js,但是执行phantomjs文件时仍然出现错误.正确的使用方法是什么?

I have tried to include es5-shim.js using require(), but I am still getting error when I execute the phantomjs file. What is the correct way to use this?

推荐答案

我在

I tried the polyfill in this link and it seems to work fine for me.

请注意,phantomjs脚本在WebKit的 JavaScriptCore 引擎(使用ES5)中运行功能应该已经开箱了.

Note that phantomjs scripts run inside WebKit's JavaScriptCore engine (which uses ES5) so most of these functions should already come out of the box.

D:\>phantomjs.exe

phantomjs> console.log(Object.keys)
function keys() {
    [native code]
}
undefined

phantomjs> var shim = require("D:\\es5-shim.js");
undefined

phantomjs> console.log(Object.keys)
function keys(object) {
        if (isArguments(object)) {
            return originalKeys(ArrayPrototype.slice.call(object));
        } else {
            return originalKeys(object);
        }
    }

这篇关于为PhantomJS绑定polyfill的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆