栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

CasperJS绑定问题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CasperJS绑定问题

如果使用了PhantomJS 2,则不再需要下面的垫片。不幸的是,CasperJS1.1-beta3还不支持它,因此您可能想要使用GitHub的master分支。


问题是PhantomJSv1.x不支持

Function.prototype.bind
。您需要为此添加垫片。在CasperJS中,它进入
page.initialized
事件处理程序。此匀场片对我在instragram上效果很好:

casper.on( 'page.initialized', function(){    this.evaluate(function(){        var isFunction = function(o) {          return typeof o == 'function';        };        var bind,          slice = [].slice,          proto = Function.prototype,          featureMap;        featureMap = {          'function-bind': 'bind'        };        function has(feature) {          var prop = featureMap[feature];          return isFunction(proto[prop]);        }        // check for missing features        if (!has('function-bind')) {          // adapted from Mozilla Developer Network example at          // https://developer.mozilla.org/en/Javascript/Reference/Global_Objects/Function/bind          bind = function bind(obj) { var args = slice.call(arguments, 1),   self = this,   nop = function() {   },   bound = function() {     return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments)));   }; nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined bound.prototype = new nop(); return bound;          };          proto.bind = bind;        }    });});

如果将填充程序导出到其自己的文件中并通过该

clientscripts
选项包括在内,则不起作用,因为这些附加程序已附加到instagramjavascript之后,为时已晚。

注册

page.resource.received
事件也可能有用。

还有一个纯粹的PhantomJS问题:为PhantomJS绑定polyfill



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号