|
28 | 28 | func = _.bind(func, this, 'hello', 'moe', 'curly'); |
29 | 29 | equal(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments'); |
30 | 30 |
|
31 | | - func = function(context, message) { equal(this, context, message); }; |
32 | | - _.bind(func, 0, 0, 'can bind a function to `0`')(); |
33 | | - _.bind(func, '', '', 'can bind a function to an empty string')(); |
34 | | - _.bind(func, false, false, 'can bind a function to `false`')(); |
35 | | - |
36 | 31 | // These tests are only meaningful when using a browser without a native bind function |
37 | 32 | // To test this with a modern browser, set underscore's nativeBind to undefined |
38 | 33 | var F = function () { return this; }; |
39 | 34 | var boundf = _.bind(F, {hello: 'moe curly'}); |
40 | 35 | var Boundf = boundf; // make eslint happy. |
41 | 36 | var newBoundf = new Boundf(); |
42 | | - equal(newBoundf.hello, undefined, 'function should not be bound to the context, to comply with ECMAScript 5'); |
| 37 | + equal(newBoundf.hello, 'moe curly', 'function should not be bound to the context, because this ain\'t ECMA5'); |
43 | 38 | equal(boundf().hello, 'moe curly', "When called without the new operator, it's OK to be bound to the context"); |
44 | | - ok(newBoundf instanceof F, 'a bound instance is an instance of the original function'); |
| 39 | + ok(!(newBoundf instanceof F), 'a bound instance is not an instance of the original function'); |
45 | 40 |
|
46 | 41 | throws(function() { _.bind('notafunction'); }, TypeError, 'throws an error when binding to a non-function'); |
47 | 42 | }); |
|
62 | 57 |
|
63 | 58 | func = _.partial(function() { return typeof arguments[2]; }, _, 'b', _, 'd'); |
64 | 59 | equal(func('a'), 'undefined', 'unfilled placeholders are undefined'); |
65 | | - |
66 | | - // passes context |
67 | | - function MyWidget(name, options) { |
68 | | - this.name = name; |
69 | | - this.options = options; |
70 | | - } |
71 | | - MyWidget.prototype.get = function() { |
72 | | - return this.name; |
73 | | - }; |
74 | | - var MyWidgetWithCoolOpts = _.partial(MyWidget, _, {a: 1}); |
75 | | - var widget = new MyWidgetWithCoolOpts('foo'); |
76 | | - ok(widget instanceof MyWidget, 'Can partially bind a constructor'); |
77 | | - equal(widget.get(), 'foo', 'keeps prototype'); |
78 | | - deepEqual(widget.options, {a: 1}); |
79 | 60 | }); |
80 | 61 |
|
81 | 62 | test('bindAll', function() { |
|
0 commit comments