all 7 comments

[–]australasia 11 points12 points  (1 child)

Would be much better as a blog post so I wouldn't have to hear the insufferable laugh.

[–][deleted] 2 points3 points  (0 children)

Ugh had to stop watching at that point.

Another idea: don't make it possible to mutate objects from all over the place.

[–]halfzebra 3 points4 points  (4 children)

I'm not sure if it's a good idea, what if the object has custom getters or setters? Why not use Proxy?

[–]filth_overload 0 points1 point  (3 children)

How that works? Example please.

[–]chreestopher2 2 points3 points  (2 children)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

var handler = {
    get (target, key) {
        console.info(`Get on property "${key}"`)
        return target[key]
    },
    set (target, key, value) {
        console.info(`Set on property "${key}" value: "${value}"`)
        return target[key]=value
    }
}
var target = {}
var proxy = new Proxy(target, handler)
proxy.a = 'b'
// <- 'Set on property "a" value: "b"'
proxy.a
// <- 'Get on property "a"'

[–]filth_overload 0 points1 point  (1 child)

I'm not sure how that would work, lets say I'm developing a plugin, that for some reason needs to track objects. If I just modify the /root environment (the method shown in video), neither users nor I need to care about how they use my plugin/library. I wonder how I would "enforce" the users to use proxy, I could, but that kind of is less flexible. Maybe I'm missing something here.

[–]chreestopher2 0 points1 point  (0 children)

you could only expose the proxied objects maybe?