es-shims/es5-shim

Why not set bound.prototype = target.prototype directly?

LongTengDao opened this issue · 3 comments

bound.prototype = new Empty();

function f () {}
var b = f.bind({});
new f instanceof b;// true in native, but false in shim

When I overwrite Function.prototype.bind in my current browser with the shim's implementation, new f instanceof b returns true for me. In what browser are you seeing it return false?

(Note that it would be incorrect to set it directly; b.prototype !== f.prototype in native)

<!DOCTYPE html>
<html>
	<head>
		<title></title>
		<script src="./es5-shim.js"></script>
	</head>
	<body>
		<script>
			function F () {}
			var B = F.bind([]);
			var f = new F;
			document.write(f instanceof B);
		</script>
	</body>
</html>

IE 6 7 8 all print false.

In current shim, B.prototype is instance of F, in other words, new F and B.prototype are same level instance.

(! ( B.prototype instanceof F ) in native too)