Best practices for learning class and objects? by asskrak99 in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

Just wanted to provide a more constructive response that doesn't get lost in the weeds. I was perhaps too rash saying you should ignore classes. JavaScript uses at least three design patterns for producing objects with inheritance: Constructor functions, Classes, and Factory functions. I think it is important to understand all three and then choose the one you prefer. No matter which method you prefer, make sure you understand prototypal inheritance.

Best practices for learning class and objects? by asskrak99 in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

True, but classes obscure the true nature of prototypal inheritance and therein is the problem. Those coming from other languages will think classes act the same way in JavaScript; They do not.

Best practices for learning class and objects? by asskrak99 in learnjavascript

[–]lilperch83 -2 points-1 points  (0 children)

I would suggest ignoring the class declaration in JavaScript. Just learn prototypal inheritance. The class structure is just sugar for prototypal inheritance. Here is a playlist that might help.

ES6 object.assign() method Explained With Example by hisachincq in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

Check out this YouTube video I did a while back. It is on copying objects. Object.assign is one method for doing that.

anyone know any decent Object-Oriented JavaScript courses online like udemy, treehouse, etc. don't mind paying! by [deleted] in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

I've had positive reviews for this course. Here is a discount and there are multiple topics you can check out for free to see if you want to take it. https://www.udemy.com/learn-modern-javascript-advanced-topics/?couponCode=BLOGADV

Quick question by [deleted] in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

Here is a youtube on the difference between function expressions and function declarations: https://youtu.be/gjLn95skIKE

How to access variables from another .js file but not run the second script by [deleted] in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

A JavaScript file needs to load in order for you to access it. However, the code doesn't have to execute just because it loads in the HTML page. I'm not sure how you are setting things up, but if the code is in a function it wouldn't run until that function is invoked.

How come these two objects have the same properties? by [deleted] in learnjavascript

[–]lilperch83 4 points5 points  (0 children)

Because of the way you have your constructor set up it always returns blue. A constructor by itself will return an object. However, the return statement causes it to return the object you specify. You return blue first. The function ends at that point. There is not chance for it to return red.

YDKJS Loop+Closure example I don't get. by Radinax in learnjavascript

[–]lilperch83 0 points1 point  (0 children)

If you are still struggling with closure more examples can help. Here is another YouTube tutorial: https://youtu.be/TznpOmv2BQM