in my continued quest to sin myself directly into ...
# linking-together
g
in my continued quest to sin myself directly into hell with my side project, i realized that i wanted to have a member of an array replace itself as the result of a method call, and the natural way to do that seemed to be something like having the last line of the method be
this = newObject
. that’s impossible in javascript—`this` is immutable and i’m not even sure how you’d update all the references in a coherent way (although i’m pretty sure it would make sense if you were doing enough pointer indirection). does anyone know of any cursed programming systems that let you do that kind of thing? i think there’s kind of an analogy in terms of replacing a server at a certain domain—all the hyperlinks stay pointing right at your new object
i
You want pointers rather than references. You’d then change what’s at the pointer’s location, while leaving the pointer as is.
d
In C++ you write
*this = newObject;
.
a
In JS, can you just delete all existing fields on this and update with your new object? It's probably possible to do similar things in Python, as long as your remember to update the prototype, class, etc.
m
i
You thinking something like
Array.prototype.map
but that mutates the array rather than returning a new array? Or are you thinking something like...
arr[x] = fn(arr[x])
, but where the function somehow knows about the array so that you can just call it like
fn(arr[x])
and it takes care of updating the array? Or are you basically asking for
become:
? Your domain / hyperlink example makes it seem like that's what you're after, and in this case the fact that arrays are involved is irrelevant. Let me know what you want the calling context to look like, and I'll see if I have anything in one of my dustier tomes.
g
@Ivan Reese it’s more like
become
, i think. specifically i’m experimenting with going all out on the idea of message networks (making up this vocab as i go along)—so instead of
map
or
cata
, i’m seeing if i can do stuff like have arrays “broadcast” messages to their children recursively. something like:
Copy code
Array.prototype.broadcast = function(message) {
this.map(i => i.broadcast? i.broadcast(message) : i[message]())
}
so ideally the objects in an array would update themselves in-place without having to reassign at the array-level/parent-level abstraction, if that makes sense turns out my mental model of references as “pointers with extras” was wrong lmao—thank you @ibdknox @Mariano Guerra this is gold i had never heard of
become
before thank you
sorry the formatting is screwy i’m on my phone
w
Thanks @Mariano Guerra. I came here to mention
become:
. Works well for state machines.