@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?
@aescling @vaporeon_ did you know C++ has both pointers and references :D
@vaporeon_ @aescling they do function as aliases to an existing object but they still pass by value when given to functions, so they can be used in any situation where a pointer can be used because C++ likes giving you multiple ways to solve every problem
@wallhackio @aescling Is there a meaningful performance difference? I could imagine that maybe the compiler could optimize more when using a reference, because pointers can point anywhere in the memory and references can't?
@vaporeon_ @aescling there's no optimization in using a reference over a pointer, it's a style thing
@wallhackio @aescling Really? I've been told that pointers are somewhat of a trouble for modern optimizing compilers because the user can always do some pointer arithmetics with them and there's no guarantee that they point at a valid value and that prevents some optimizations (I don't remember which ones)...
So references don't help with that?
@vaporeon_ @aescling oh you might be right actually.
@wallhackio @vaporeon_ yeah you don’t have pointer arithmetic at all in js. basically all implementations are using pointers under the hood and just not allowing the purrogrammer to manipulate the address they point to
@aescling @wallhackio I was asking about C++ 😅
Because Clodsire brought up that C++ has both pointers and references
@vaporeon_ @wallhackio oh lol
@wallhackio @aescling I did! I have a lot of trouble with the concept of references that are not pointers, but as far as I understood, it's just telling the compiler a different name for the same variable? Sort of like
EQUIVALENCE
in FORTRAN?