Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LongTengDao opened this issue Jun 25, 2019 · 3 comments
Open

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

LongTengDao opened this issue Jun 25, 2019 · 3 comments

Comments

@LongTengDao
Copy link

bound.prototype = new Empty();

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

ljharb commented Jun 25, 2019

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?

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

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

@LongTengDao
Copy link
Author

LongTengDao commented Jun 26, 2019

<!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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants