description("Tests Function.bind.");
var result;
function F(x, y)
{
result = this + " -> x:" + x + ", y:" + y;
}
G = F.bind("'a'", "'b'");
H = G.bind("'Cannot rebind this!'", "'c'");
F(1,2);
shouldBe("result", '"[object Window] -> x:1, y:2"');
G(1,2);
shouldBe("result", '"\'a\' -> x:\'b\', y:1"');
H(1,2);
shouldBe("result", '"\'a\' -> x:\'b\', y:\'c\'"');
var f = new F(1,2);
shouldBe("result", '"[object Object] -> x:1, y:2"');
var g = new G(1,2);
shouldBe("result", '"[object Object] -> x:\'b\', y:1"');
var h = new H(1,2);
shouldBe("result", '"[object Object] -> x:\'b\', y:\'c\'"');
shouldBeTrue('f instanceof F');
shouldBeTrue('f instanceof G');
shouldBeTrue('f instanceof H');
shouldBeTrue('g instanceof F');
shouldBeTrue('g instanceof G');
shouldBeTrue('g instanceof H');
shouldBeTrue('h instanceof F');
shouldBeTrue('h instanceof G');
shouldBeTrue('h instanceof H');
shouldBeTrue('"prototype" in F');
shouldBeFalse('"prototype" in G');
shouldBeFalse('"prototype" in H');
shouldThrow('Function.bind.call(undefined)');
var abcAt = String.prototype.charAt.bind("abc");
shouldBe('abcAt(1)', '"b"');
shouldThrow('new abcAt(1)');
var boundFunctionPrototypeAccessed = false;
P = F.bind(1,2);
Object.defineProperty(P, 'prototype', { get:function(){ boundFunctionPrototypeAccessed = true; } });
f instanceof P;
shouldBeFalse('boundFunctionPrototypeAccessed');
shouldBe('Function.bind.length', '1');