@wallhackio The JavaScript Planet, a dystopian world where JavaScript is the only programming language ever invented
@vaporeon_ I love JavaScript, so delete this please
@vaporeon_ I love JavaScript, so delete this
please
@wallhackio How do I deallocate memory / destroy an object in JavaScript? So that I can delete this
?
@vaporeon_ npm install memory-management
@wallhackio Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
And in standard JavaScript? No NPM?
@vaporeon_ it was a joke lmao
@wallhackio But can you do any memory management in JavaScript?
const deleteThis = () => {
const temp = { _this: this };
delete temp._this;
};
@aescling @vaporeon_ this will NOT do what it's being promised to do, this is a joke
@wallhackio @aescling What will it do?
@vaporeon_ @aescling it will create an object with a single property named _this
that has the value of whatever this
was where the arrow function was declared
and then it will delete that property from the object
@wallhackio @aescling So creating the object initializes _this
with a copy of the value of this
, and only that copy gets deleted?
@vaporeon_ @aescling yessir
@wallhackio @vaporeon_ not a copy but a refurence
@wallhackio @vaporeon_ what gets deleted is the refurence
@aescling @wallhackio Is a reference the JavaScript version of a pointer?
@vaporeon_ @wallhackio yeah basically
const o = { k: 1 };
function changeObj(o) {
o.k = 2
};
changeObj(o);
console.log(o); // { k: 2 }
@aescling @wallhackio LOL, is that because the pointer is a constant, but the contents of the object are not? In C terms, what happens here is this, right?
changeObj(struct object *o) {
o->k = 2;
}
main() {
const struct object *o = new_object(1);
changeObj(o);
printf("k: %d\n", o->k);
}
@aescling @wallhackio There are two types of languages: those that have explicit pointers and those that hide the concept of a pointer from the user and therefore become very confusing
@vaporeon_ @wallhackio if you purrogram enough with pass-by-refurence languages you just get used to it