Where can I find an explanation of how Arrays, typed arrays, and ArrayBuffers behave when you do things like:
var array2=array1
I know that sometimes it creates a copy, and other times something called a "view", which I don't understand.
How does this work? Right now, I've been explicitly doing:
var array2=new Uint8Array(array1); //or whatever type of array it is
every time I need to do anything like this, because this is the only way that I understand the behavior of.
Where can I get more information on this? AFAIK, this isn't standard javascript (I certainly wasn't able to find anything about typed arrays and array views)... So yeah, I'm kinda baffled, and think it's likely that I could write better code if I understood how this worked, but I can't find any explanations of what these are, and how they work.
I think I also don't understand this on a conceptual level - I don't comprehend why these "views" and why things-that-look-like-copies-and-are-created-like-copies-but-aren't-copies* are a good thing. Why define a new variable if you're not copying the data? What is the benefit? I already have the array, why not just refer to it instead of creating... what amounts to an alias to it.
My initial reactions when running into it was profanity-laden exclamations accusing the unknown language-designer who made this system of mental deficiencies, satanic inspiration, despicable perversions and general malice toward programmers. But yeah, I think I must be missing something here. Be aware that while I work on programming at work and in my free time, I didn't major in CS (advanced degree in the wrong technical major - one much harder to get through, but which I could never deal with the work culture in. Biggest mistake of my life) - I think that if I did, I might have learned about these in school.
*that is, it fails the duck test - it hatches from a duck egg, looks like a duck, quacks like a duck, but when you pluck it and roast it up, it's mom back in the pond gets cooked up too.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Where can I find an explanation of how Arrays, typed arrays, and ArrayBuffers behave when you do things like:
I know that sometimes it creates a copy, and other times something called a "view", which I don't understand.
How does this work? Right now, I've been explicitly doing:
every time I need to do anything like this, because this is the only way that I understand the behavior of.
Where can I get more information on this? AFAIK, this isn't standard javascript (I certainly wasn't able to find anything about typed arrays and array views)... So yeah, I'm kinda baffled, and think it's likely that I could write better code if I understood how this worked, but I can't find any explanations of what these are, and how they work.
I think I also don't understand this on a conceptual level - I don't comprehend why these "views" and why things-that-look-like-copies-and-are-created-like-copies-but-aren't-copies* are a good thing. Why define a new variable if you're not copying the data? What is the benefit? I already have the array, why not just refer to it instead of creating... what amounts to an alias to it.
My initial reactions when running into it was profanity-laden exclamations accusing the unknown language-designer who made this system of mental deficiencies, satanic inspiration, despicable perversions and general malice toward programmers. But yeah, I think I must be missing something here. Be aware that while I work on programming at work and in my free time, I didn't major in CS (advanced degree in the wrong technical major - one much harder to get through, but which I could never deal with the work culture in. Biggest mistake of my life) - I think that if I did, I might have learned about these in school.
*that is, it fails the duck test - it hatches from a duck egg, looks like a duck, quacks like a duck, but when you pluck it and roast it up, it's mom back in the pond gets cooked up too.