tc39 / proposal-bind-operator

This-Binding Syntax for ECMAScript
1.75k stars 30 forks source link

Calling :: on Primitives #50

Open 7fe opened 7 years ago

7fe commented 7 years ago

Would the following work or not? Apologies if this has already been answered couldn't find an issue on this. I would assume the answer is an obvious yes.

"div.myClass"::find("p")::html("hahaha");
23::times(23);
[2,3]::equals([2,3]);
/1/::equals(/1/)

I would assume assume that it would work or objects not native to current page and are from an iframe yes?

EDIT: Would I need to wrap objects like the following?

{y:'z'}::test();
({y:'z'})::test();

And the following would throw an error yes?

null::f();
var x = null;
x::f();
michaelficarra commented 7 years ago

Primitives can be used as this values in modern JavaScript engines just fine. It should work.

robotlolita commented 7 years ago

All of these are compiled like so: a::b(c) => b.call(a, b). None of them will throw an error. In older engines a would be boxed.

elado commented 6 years ago

looks like "use strict" solves that see related issue https://github.com/elado/lodash-bound/issues/1