Fork me on GitHub
#cljs-dev
<
2022-08-22
>
thheller06:08:00

might be for historic reasons. I do remember some browsers (at least IE) not doing too well with extending native types

dnolen13:08:51

@lilactown I think the idea is that you have to control the protocol or the type

dnolen13:08:05

if you use a protocol and a type you don’t control then you will have conflicts

pithyless13:08:51

> if you use a protocol and a type you don’t control then you will have conflicts I recall the case of MooTools monkeypatching core JS objects causing trouble for newer ECMAscripts, with conflicting methods changing underlying semantics. Are there are other good examples where this wasn't just a theoretical problem?

dnolen14:08:45

it happened all the time - in the early days it prevented using different libs together on the same webpage

dnolen14:08:36

definitely not theoretical issue - really a nightmare

lilactown15:08:25

does the introduction of Symbol and extending built ins using them eliminate most of the risk of conflicts?

borkdude16:08:41

@lilactown If you own the protocol, what is exactly the risk?

lilactown16:08:15

that's what I'm wondering

borkdude16:08:25

You either own the protocol OR the type, you don't have to own them both

borkdude16:08:13

Symbol is a means to an end, a unique string property would have the same effect I think?

borkdude16:08:52

(although as you pointed out, this stuff is done using Symbols now in JS)

lilactown16:08:07

yeah, there's certain other nice properties of using symbols that don't have to do with avoiding conflicts

lilactown16:08:24

you don't have to use Symbol.for. Symbol("foo") creates a completely unique symbol each time, so as long as you can reference the value returned by it, using Symbol.for is not needed and you can avoid conflicts compeletely

lilactown16:08:59

but also, Symbols as properties on objects don't show up in the enumerable properties of objects, so you can avoid problems with serialization too

borkdude16:08:09

so if have an object {} and do {}[Symbol("foo")] = 1 twice, it has two new properties?

borkdude16:08:34

verified:

> x = {}
{}
> x[Symbol("foo")] = 1
1
> x[Symbol("foo")] = 1
1
> Object.getOwnPropertySymbols(x);
[ Symbol(foo), Symbol(foo) ]

lilactown16:08:27

I guess if it's just MooTools-esque conflicts or old versions of IE to worry about (which I don't care), then a new language could use Symbols for protocols and extend built ins directly

👍 1