![]() |
Log In |
Home | Forums | Shops | Trade | Avatar | Inbox | Games | Donate |
Not Logged In |
![]() |
|
Thread Tools |
Potironette
![]() petite fantaisiste
![]() ![]() |
![]() |
#65 | ||
Thanks again for the detailed answers!
Hmm, so for images, would it be window.img.addEventListener('load', aasdf); ? I'm sort of fumbling around looking at javascript and copying them down in hopes of understanding enough to make my own moving things eventually. In general, when one uses javascript..is it that they make "function"s and put variables in them with things that get done to those variables? And then I just need to learn the jargon? What's an object? That is, what's the difference between an object and a variable..? So, a method/member function is a function that has it thing it's inside? And "this" means the thing it's inside? So window.addEventListener('load', somefunction) means addEventListener is a function inside something that's a "window"? And for some reason the window is whatever a "this" is..? Also, why is it that 'load' is in quotes? And does addEventListener basically waits/listens for 'load' of the "this" then the comma means after the comma it does somefunction? Why is somefunction an object..? Or what does it mean that the function is an object..? Defined on..means it's based on..? To invoke is to have something done..? ![]() | ||||
![]() | Posted 01-05-2017, 01:34 AM |
![]() |
![]() |
#66 |
Coda
![]() Developer
![]() ![]() |
||
Seems I need to back up a level -- overestimated your past experience. I'm going to rearrange my response instead of answering your questions in order, so that I can build on what I'm saying.
So... First off. A variable is a name you use to refer to something. What is that something? Anything you assign to it. When you say "x = 1" you're saying "from here on, when I say 'x', I really mean '1'." When you say "y = x" you're saying "whatever thing I was calling x before, I also want to be able to call it y (feel free to go ahead and use x to refer to something else if you want)." There are some nitpicky details that vary from language to language about what the = there actually DOES. I'll stick to Javascript for this post, and I'll try to be as general as possible so that it DOES apply broadly, but you should be aware that there are other ways that things happen that do in fact come up in some modern programming languages. In Javascript in particular, variables are references to values. If you change part of that value, then you can see that change through every variable pointing to that value. Of course, you can't change the value of the number 1, so it's irrelevant there, but if the value is an object, it matters. More on this below. It's... actually really hard to explain what an object is in concrete terms because there are several different definitions with a lot of overlap that get used in a fuzzy way. The simplest definition of "object" that I think I can give is that it's a value made up of other values in a structured way. This definition jives with most (but not all) of the ways the term "object" gets used. In particular, when I referred to treating a function as an object, that's one of the definitions that doesn't jive. *sweatdrop* In THAT case, "object" means any value that can be referred to and moved around as a single entity, regardless of what it's made of. In many languages, functions and values are completely different and you can't give one function to another function for it to use; in Javascript, you can store a function in a variable just like any other object. In Javascript, you can create a new plain object using {}, and you can access parts of an object using the . operator. Code:
var x = {}; x.a = 1; x.b = 2; x.a + x.b // 3 Code:
var x = { a: 1, b: 2 }; x.a + x.b // still 3 Some kinds of objects have stuff preloaded onto them. For example, the "document" object that a web browser gives you has "body" and "getElementById" preloaded into it. Usually you can add new stuff. Sometimes you can't. At your level, best to assume you can't, because adding stuff to objects you didn't make can make things confusing to reason about. So basically, the difference between a variable and an object is that an object is a concrete thing that has some value to it, and a variable is a name that points at one (or possibly zero) of those concrete things. EDIT: I said I'd come back to it, and here it is. A variable can only point at one object, but you can have multiple variables pointing at the same object. A quick demonstration: Code:
var x = { a: 1, b: 2 }; var y = x; y.a // 1 y.a = 3; x.a // 3 now Invoke is a jargon term that's basically synonymous with "execute"/"run"/"call". The specific meaning of invoke is that you're intentionally and directly pointing at a function and telling it to do its thing. A method is a function accessed through an object that does things with that object. In Javascript, a function that you invoke as a method has the special variable "this" refer to the containing object. In your specific example: Yes, "addEventListener" is a function inside the object called "window", and so you can say that it is a method of "window". If you could look at the code inside "addEventListener" (you CAN'T, but if you COULD) you would see that it would be using "this" inside, and when you call it as "window.addEventListener" then "this" would be the same as "window". If, on the other hand, you had taken a button from the page and called "button.addEventListener" then "this" inside would be the same as "button". The reason "load" is in quotes is because events (a jargon word meaning "things that happen from outside of your code, and you can do something when they occur") in Javascript are referred to by string names. There's nothing particularly magical about it. The browser just says "okay, everything on the page is done loading, so I'm going to see who added event listeners for the event named 'load' and invoke them." For "addEventListener" in specific, the first parameter is the name of the event, and the second parameter is the function (not the name of the function, the function itself) that you want the browser to invoke when the event "fires" / is "dispatched." It should be noted that this function doesn't WAIT for anything -- the code below it keeps running. When an event happens, the browser dispatches it as soon as there isn't any other Javascript code running. Your description of writing Javascript code is... well, it's not WRONG. A function IS, at its core, a list of instructions of what to do to the variables the function can see. I think that covers everything you were asking for? EDIT: Oops, forgot to go back and touch on my "more on this below". Editing that in with a second edit... Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-05-2017, 03:25 AM |
![]() |
Potironette
![]() petite fantaisiste
![]() ![]() |
![]() |
#67 | ||
Yep! That covers everything! Thanks a lot!
My so called past experience is basically nothing xD. I just like to mess around and I find this interesting but confusing. The var x = {} reminds me of learning about sets in math. Is var x = {} basically that the set that's x is currently empty? Out of curiosity, when you have var x = { a: 1 } can you only get the a from x? That is, var a = { x: 3 } isn't going to affect anything? ![]() | ||||
![]() | Posted 01-05-2017, 03:37 PM |
![]() |
![]() |
#68 |
Coda
![]() Developer
![]() ![]() |
||
Yes. That's the whole fundamental point of objects -- every object is self-contained. Two distinct objects won't have any effect on each other, and the stuff inside an object is unrelated to the stuff outside the object.
It should also be noted that names have scopes. That is, a given name is only applicable inside a certain region. If you define a variable outside of any functions, that variable is global and everything can see it, unless you declare a new variable inside a function (with the "var" keyword) then that one will hide the global one. If you have a function defined inside a function (way more common than you might expect) then variables in the outside function are visible to the inside function, but not vice versa. Names in objects are the same way -- the names of the properties are scoped to the object. The name has no meaning anywhere except when referring to a property of that specific object. Every "a" in this example is distinct and unrelated to the others: Code:
var a = 3; var b = 'b'; var x = { a: 1 }; var y = { a: 2 }; // you can only see b here function foo() { var a = 4; var c = 'c'; // you can see b and c here function bar() { var a = 5; var d = 'd' // you can see b, c, and d here } // back outside of the definition of bar, you can only see b and c here } x.a = 6; // y.a is still 2, because they're separate objects As far as the syntax... Yes, it's probably inspired by set notation historically. No, you probably shouldn't try to think of them as sets, because they don't really act like sets -- you can't easily see how full an object is or if it's empty, and two empty objects aren't equal to each other. It's better to think of them as dictionaries -- if you have a name, you can look up what it means inside. EDIT: It occurs to me that you used "window.img" in an earlier post and I forgot to respond to that. Accessing images on the page... doesn't work like that. :P But you can put an "id" attribute on an <img> tag and use "document.getElementById" to get that in your script, then store that in a variable. Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-05-2017, 05:05 PM |
![]() |
Potironette
![]() petite fantaisiste
![]() ![]() |
![]() |
#69 | ||
Thanks, that makes a lot of sense! As of now I don't have another question xD
![]() | ||||
![]() | Posted 01-06-2017, 02:54 AM |
![]() |
![]() |
#70 |
Potironette
![]() petite fantaisiste
![]() ![]() |
||
"While horizontal integration sometimes brought economies and greater profits, monopolistic control over prices did boost earnings."
^A sentence from my US history textbook. I'm guessing economies means not cost efficient, but I can't fathom why greater profits deserves a "while." I guess this question might fall outside the category of English though :/. It's probably important for me to understand it for school, at least. ![]() | ||||
![]() | Posted 01-07-2017, 12:35 PM |
![]() |
Coda
![]() Developer
![]() ![]() |
![]() |
#71 | ||
No, on the contrary, an economy in this context means something that IS cost-efficient -- things like discounts for buying in bulk ("economy-size").
What that statement is saying is that being a monopoly made money for the company by reducing operating costs, but monopoly companies could also make money by controlling how much they charged for things, because customers couldn't just go to a competitor for a better deal. In your defense, that's a REALLY poorly written sentence. Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-07-2017, 01:31 PM |
![]() |
![]() |
#72 |
Potironette
![]() petite fantaisiste
![]() ![]() |
||
Ohh, okay, that makes sense. The textbook also said:
"Companies that integrated vertically frequently achieved economies of scale through more efficient management techniques." So is "economies of scale" and the "economies" of the horizontal integration the same thing..? ![]() | ||||
![]() | Posted 01-07-2017, 01:43 PM |
![]() |
Coda
![]() Developer
![]() ![]() |
![]() |
#73 | ||
Economy of scale is a specific kind (possibly the most common kind) of economy. A business could also derive an economy from, for example, being able to choose among providers.
In vertical integration, controlling the whole supply chain means you spend more money up front to get a system set up that does EXACTLY what you need it to do and nothing else, so that you save money in the long run. This is an economy of scale because that kind of setup only works if you need a WHOLE BUNCH of the same thing for a long time. EDIT: Also, vertical integration means that it's okay for individual components of the supply chain to operate at a loss if the profit of another component makes up for it -- you don't have each business in the chain marking up the prices a little in order to make a profit. Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-07-2017, 01:55 PM |
![]() |
![]() |
#74 |
Potironette
![]() petite fantaisiste
![]() ![]() |
||
Ohh, so the difference between Andrew Carnegie and Rockefeller was that Carnegie used a ton of money to get things set up and Rockefeller used a ton of money to drive out competitors (the textbook had been using them a lot as examples).
I'm guessing that economy is just a term referring to how business is managed then..? ![]() | ||||
![]() | Posted 01-08-2017, 06:18 AM |
![]() |
Coda
![]() Developer
![]() ![]() |
![]() |
#75 | ||
It's a term referring to a way to save money.
And yeah, that's probably a reasonable way to look at it. Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-08-2017, 12:15 PM |
![]() |
![]() |
#76 |
Potironette
![]() petite fantaisiste
![]() ![]() |
||
Ohh, so that's what the "economy"'s supposed to be for. It kind of became a word to throw around in history class for me :x.
Thanks a lot! I would have just given up on actually understanding that part of the text otherwise ><' ![]() | ||||
![]() | Posted 01-08-2017, 03:07 PM |
![]() |
Potironette
![]() petite fantaisiste
![]() ![]() |
![]() |
#77 | ||
Where does
Delta x = 1/2(vi + vf)Delta t come from? We were learning about momentum, and something about impulse(?), but I'm not too sure because I was half-asleep that day. ![]() | ||||
![]() | Posted 01-12-2017, 06:00 AM |
![]() |
![]() |
#78 |
Coda
![]() Developer
![]() ![]() |
||
Δx = 1/2(vi + vf)Δt
The change in position equals the average velocity multiplied by the change in time. In this case, you're using constant acceleration, so the average velocity can be found by averaging the initial and final velocities. Impulse is a measurement of the change in momentum caused by a force applied over time. A big force over a short time can have the same impulse -- that is, the same change in momentum -- as a small force over a long time. In the case of a constant force, it's just F*Δt. Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-12-2017, 11:34 AM |
![]() |
Potironette
![]() petite fantaisiste
![]() ![]() |
![]() |
#79 | ||
Δ Huh, that's odd. Wherever I got the triangle from (I forget), it turned into a capital "D"
Ohh, so when velocity changes constantly, the velocity of that total time is just the average of the velocities at time 1 and time 2 then it just so happens that velocity is distance over time and so the total distance over that time is Δx = 1/2(vi + vf)Δt ? Oh wow, that's really cool. I wonder why it works out that change in momentum is the same as a constant net force multiplied by the change in time? Why is mv called "momentum" and why is change in momentum called "impulse"? Or is that something I just need to remember.. ![]() | ||||
![]() | Posted 01-13-2017, 05:35 PM |
![]() |
![]() |
#80 |
Coda
![]() Developer
![]() ![]() |
||
It was probably using a Greek font with the letter D instead of using the Unicode uppercase delta symbol.
If it helps a light bulb turn on in your head, consider this: If you know how far the object moved in a certain span of time -- that is, if you know Δx and Δt -- then you can use the formula for velocity you already know: velocity = distance / time. This is actually measuring the average velocity. No matter what path the object took, whether it was moving at a constant speed or if it sped up or slowed down or even went two-steps-forward-one-step-back the whole time, as a whole, the velocity balances out to this value. So OF COURSE if you go for that period of time averaging that velocity you'll go that distance! So that just leaves the special case of constant acceleration. The assertion is that the average velocity under constant acceleration is the average of the initial and final velocity (that is, (vi + vf)/2). "But Coda," someone might ask, "what about all of the velocities in between? Why don't they count?" To which I say: Consider any two points in time equidistant from the middle. The initial and final velocities are obviously such a pair, but you might look at 25% into the time span and 75% into the time span, or 10% and 90%. No matter what pair you pick, because it's constant acceleration those two points will always average to the same value -- the velocity at exactly 50%. As for why mass * velocity = change in momentum = force * time, well, dimensional analysis is a useful tool here. The units of velocity is m / s. The units of momentum is kg * m / s. The units of force is kg * m / (s^2). And obviously the units of time is s and the units of mass is kg. So... mass * velocity = momentum = force * time kg * m / s = kg * m / s = kg * m / s (If this makes you wonder if these equations can be used to deal with a change in mass, then good on you for being curious -- the answer is "yes, that's what they use for rockets as they burn fuel.") As for the names "momentum" and "impulse", that's just something you have to remember. "Momentum" is named that because it more or less matches up with the vernacular usage of the word. The term "impulse" was chosen because the common usage of the word means "push" or "drive". Games by Coda (updated 4/8/2025 - New game: Marianas Miner)
Art by Coda (updated 8/25/2022 - beatBitten and All-Nighter Simulator) Mega Man: The Light of Will (Mega Man / Green Lantern crossover: In the lead-up to the events of Mega Man 2, Dr. Wily has discovered emotional light technology. How will his creations change how humankind thinks about artificial intelligence? Sadly abandoned. Sufficient Velocity x-post) | ||||
![]() | Posted 01-13-2017, 06:24 PM |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|