forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.function.bind.js
28 lines (28 loc) · 907 Bytes
/
es.function.bind.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
QUnit.test('Function#bind', assert => {
const { bind } = Function.prototype;
assert.isFunction(bind);
assert.arity(bind, 1);
assert.name(bind, 'bind');
assert.looksNative(bind);
assert.nonEnumerable(Function.prototype, 'bind');
assert.same(function () {
return this.a;
}.bind({ a: 42 })(), 42);
assert.same(new (function () { /* empty */ })().a, undefined);
function A(a, b) {
this.a = a;
this.b = b;
}
const instance = new (A.bind(null, 1))(2);
assert.true(instance instanceof A);
assert.same(instance.a, 1);
assert.same(instance.b, 2);
assert.same((it => it).bind(null, 42)(), 42);
const regExpTest = RegExp.prototype.test.bind(/a/);
assert.true(regExpTest('a'));
const Date2017 = Date.bind(null, 2017);
const date = new Date2017(11);
assert.true(date instanceof Date);
assert.same(date.getFullYear(), 2017);
assert.same(date.getMonth(), 11);
});