There is also a big difference b/w creating a new instance of an array (new Array()) and just creating an empty one (myArray = ). The latter is preferable. I didn’t know the former was an option before, and that helps me better understand how JS works, but sounds like I should stick to what I’ve been doing.
Jumping back and forth between reading and writing code for Ruby and JS is both confusing, but also raises an interesting thought process. I am intrigued to learn about how related to objects JS as, and how that might play into what I’ve learned about object-oriented program during my recent foray into Ruby. Could I think of JS objects more not just as a place to collect methods (and that was a reach beyond just jumping functions everywhere), but attaching information of a certain type, to better organize code. And is the state of those values I could attach a way to keep track of application state, what a certain piece of the app is doing at a given time? As I’m writing, I think I’m finally starting to understand that may be what Backbone helps support. (Don’t quote me on that last bit, this is a space to think out loud, and it’s very likely I could be off on this; just working through the learning as I go.)
Of course, I also see the difference in languages, like how end is used at the end of a Ruby block, but causes a syntax error in JS. And the naming convention in JS is camelCase, Ruby has snake_case (see the capitals vs. underscores?). I don’t know that I’ll ever get over accidentally typing the wrong syntax in different programming files, although maybe it will get better with time.
Oh, and I’ll close with another interesting thing in terms of vocab that I learned last week, related to all this — the difference between a method and a function. A function is more generic, a block of code that does some task. A method is a function attached to an object or class. I guess kind of like a square is a specific type of rectangle. I’ve been trying to be more precise in this language in the past week or so. Always something new to learn!