Joao
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Sure but we don't know that based on the question asked. There are other things that could be pointed out that will get us off-topic for no reason...
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
but anyway, this isnt' even what this thread is about!
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
it doesn't have enough precision and it can skip back and forwards in timeYou can account for that by other means...
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Again, you don't know what the context is so you don't know whether it is suitable or not. A few milliseconds in variance might also be perfectly acceptable for this game.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Use whatever works best and worry about performance when you ahve a reason to care about performance.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Why is it wrong? You don't know the context. If the requirement is to keep a log of when a component was last active, you don't want to use relative times.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
I suspect that the millisecond variant in this case is irrelevant.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Also note, I'm using private properties here not only for correctness, but also because it allows using the same property name for the getter/setter. Otherwise you would have to do _speedY, etc.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Notice how doing this you don't even need a jump method on the parent anymore. It's nice and concise, although this may lead to challenged in either testing or debugging since now you have a single action doing multiple things: use sparingly and with caution. Or, simply "duplicate" code. As long as you understand when it really is duplicate and when it isn't.
36 replies
KPCKevin Powell - Community
•Created by Abc on 12/9/2024 in #front-end
How to avoid duplicate if checks when overriding a method in JavaScript?
Please correct me if I'm reading this incorrectly, but it seems to me that you're solving the wrong problem. Based on the code snippet provided, at least, the only reason to invoke the parent's
jump
method is to set the last activity time. First of all, I would consider the easiest and most straight forward solution to just "duplicate" the jump method on the children, with the added portion to update the speed.
I would argue that this tiny bit of duplication is worth it... in fact, I would argue this isn't duplicated code at all, even though it might seem like it. What "duplicated code" really refers to are sections of code that achieve the same goal within the same context. Two functions, or whatever, that are doing the same thing for different reasons are not duplicated code, since one could be updated at any time without affecting the other.
In this case, the parent jump
method logs the activity but the child's jump
method also updates the speedY. If you really need to do the same thing, why bother overwriting the method? That's the entire point of inheritance, take advantage of it. As an example of how you might want to change the child's jump
method, you might want to add additional checks such as isCrawling
, isSwimming
, isFlying
... since not all instances of child might have any or all of those properties, it's clear that the jump
method should be independent from the parent. Therefore, not duplicated code.
That all said, if you really want to have the activity logged whenever you update the speed (and probably other properties) consider using getters/setters:
36 replies
KPCKevin Powell - Community
•Created by Mago on 12/4/2024 in #front-end
Any recommendation for JS porfolio project?
That said, there's no reason not to use both. Make something simpler like the to-do list using vanilla JavaScript first, then you can make something else a little more challenging using React.
5 replies
KPCKevin Powell - Community
•Created by Mago on 12/4/2024 in #front-end
Any recommendation for JS porfolio project?
If the goal is showcase your skills, use whatever you like. If the goal is to practice and gaining understanding, you're much better off using vanilla JavaScript.
5 replies
KPCKevin Powell - Community
•Created by Faker on 10/7/2024 in #front-end
Meaning of FPS and how to slow down game animation
51 replies
KPCKevin Powell - Community
•Created by Faker on 10/7/2024 in #front-end
Meaning of FPS and how to slow down game animation
I suggest looking at this video, it's great to understand why rather than how:
51 replies
KPCKevin Powell - Community
•Created by theboyduddus on 9/24/2024 in #front-end
question regarding functions in js
Do you have a specific example in mind? That question is not very intuitive: you can assign a function to a variable (that's what variables are for - storing values) but you cannot assign a variable to a function.
5 replies
KPCKevin Powell - Community
•Created by Scott Borrowman on 9/10/2024 in #front-end
Question about Vuejs and disabled links
If you find out, please ping me as I'd like to know this as well 😄
36 replies
KPCKevin Powell - Community
•Created by Scott Borrowman on 9/10/2024 in #front-end
Question about Vuejs and disabled links
36 replies
KPCKevin Powell - Community
•Created by Scott Borrowman on 9/10/2024 in #front-end
Question about Vuejs and disabled links
@Scott Borrowman I think for something this specific, you might want to try at the Vue.js server directly.
36 replies
KPCKevin Powell - Community
•Created by vic on 9/10/2024 in #back-end
how to send post from data from react and capture the data in express
As an aside, do not use capital letters when defining functions. Specially in React, which requires components to be in upper case. I don't know if this is the issue here, or even if it's an issue at all when dealing with functions declared inside components, but it's just good practice.
6 replies
KPCKevin Powell - Community
•Created by vic on 9/10/2024 in #back-end
how to send post from data from react and capture the data in express
This looks like an incomplete example, I'm guessing that the component code is incorrect and the JavaScript code doesn't run to completion, running into an error.
6 replies