proposal-bind-operator icon indicating copy to clipboard operation
proposal-bind-operator copied to clipboard

Calling :: on Primitives

Open 7fe opened this issue 7 years ago • 3 comments

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();

7fe avatar Jul 26 '17 21:07 7fe

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

michaelficarra avatar Jul 26 '17 21:07 michaelficarra

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.

robotlolita avatar Jul 26 '17 22:07 robotlolita

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

elado avatar Mar 08 '18 06:03 elado