├── bind-polyfill.js ├── package.json └── README.md /bind-polyfill.js: -------------------------------------------------------------------------------- 1 | if (typeof Function.prototype.bind != 'function') { 2 | Function.prototype.bind = function bind(obj) { 3 | var args = Array.prototype.slice.call(arguments, 1), 4 | self = this, 5 | nop = function() { 6 | }, 7 | bound = function() { 8 | return self.apply( 9 | this instanceof nop ? this : (obj || {}), args.concat( 10 | Array.prototype.slice.call(arguments) 11 | ) 12 | ); 13 | }; 14 | nop.prototype = this.prototype || {}; 15 | bound.prototype = new nop(); 16 | return bound; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phantomjs-polyfill", 3 | "version": "0.0.2", 4 | "description": "Polyfill for Function.prototype.bind", 5 | "main": "bind-polyfill.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git@github.com:tom-james-watson/phantomjs-polyfill.git" 9 | }, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "keywords": [ 14 | "phantomjs", 15 | "bind", 16 | "polyfill" 17 | ], 18 | "author": "Tom Watson ", 19 | "license": "ISC", 20 | "bugs": { 21 | "url": "https://github.com/tom-james-watson/phantomjs-polyfill/issues" 22 | }, 23 | "homepage": "https://github.com/tom-james-watson/phantomjs-polyfill" 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Function.prototype.bind polyfill for PhantomJS 2 | 3 | [![npm](https://img.shields.io/npm/dt/phantomjs-polyfill.svg?style=flat-square)](https://www.npmjs.com/package/phantomjs-polyfill) 4 | [![npm](https://img.shields.io/npm/dm/phantomjs-polyfill.svg?style=flat-square)](https://www.npmjs.com/package/phantomjs-polyfill) 5 | [![npm](https://img.shields.io/npm/v/phantomjs-polyfill.svg?style=flat-square)](https://www.npmjs.com/package/phantomjs-polyfill) 6 | [![npm](https://img.shields.io/npm/l/phantomjs-polyfill.svg?style=flat-square)](https://www.npmjs.com/package/phantomjs-polyfill) 7 | 8 | This is a polyfill for function.prototype.bind which is missing from [PhantomJS](http://phantomjs.org/). 9 | 10 | ## Installation 11 | 12 | ``` 13 | npm install --save-dev phantomjs-polyfill 14 | ``` 15 | 16 | ## Usage 17 | 18 | ``` 19 | require('phantomjs-polyfill') 20 | ``` 21 | 22 | ### Usage with Karma 23 | 24 | Include the polyfill directly in the files list of your karma.conf 25 | ``` 26 | ... 27 | files: [ 28 | './node_modules/phantomjs-polyfill/bind-polyfill.js', 29 | ... 30 | ] 31 | ... 32 | --------------------------------------------------------------------------------