I am trying to add bind polyfill in my phantomjs file using es5-shim.js.
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.
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);
}
}
来源:https://stackoverflow.com/questions/24224323/bind-polyfill-for-phantomjs