Skip to content

Commit 2d87e84

Browse files
committed
Merge pull request testdouble#69 from islandr/68-bind-undefined
Added polyfill for Function.prototype.bind
2 parents dfde498 + 04acae2 commit 2d87e84

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

app/helpers/jasmine_rails/spec_runner_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def jasmine_css_files
2020
def jasmine_js_files
2121
files = Jasmine::Core.js_files
2222
if params[:console]
23+
files << 'jasmine-console-shims.js'
2324
files << 'jasmine-console-reporter.js'
2425
end
2526
files << 'jasmine-boot.js'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(function() {
2+
/**
3+
* Function.bind Polyfill for ECMAScript 5 Support
4+
* Kangax's bind with Broofa's arg optimization.
5+
* http://www.broofa.com/Tools/JSLitmus/tests/PrototypeBind.html
6+
*
7+
* Copied from https://gist.github.com/rxgx/1597825
8+
*/
9+
if (typeof Function.prototype.bind !== "function") {
10+
Function.prototype.bind = function() {
11+
var slice = Array.prototype.slice;
12+
return function(context) {
13+
var fn = this,
14+
args = slice.call(arguments, 1);
15+
if (args.length) {
16+
return function() {
17+
return arguments.length
18+
? fn.apply(context, args.concat(slice.call(arguments)))
19+
: fn.apply(context, args);
20+
};
21+
}
22+
return function() {
23+
return arguments.length
24+
? fn.apply(context, arguments)
25+
: fn.call(context);
26+
};
27+
};
28+
};
29+
}
30+
})();
31+

0 commit comments

Comments
 (0)