Object-oriented Programming in JavaScript: Made Super Simple | Mosh

Programming with Mosh · 2.3M views · 2018 · 1:02:49

Open on YouTube

Web developmentPython, Ruby & scripting languagesEducation & learningtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about JavaScript OOP, such as why methods in factory functions need `this` and how objects and closures behave.

Recommended by 2 people across 2 different months, 2018 to 2020.

What it is

A one-hour beginner course by Mosh Hamedani on object-oriented programming in JavaScript. It covers object literals, factories, constructors, prototypes, value vs reference types, private members, getters and setters, with an exercise at the end.

What people said

Recommends yuval.bl · 2018-05 · Stack Overflow · on “OO Javascript: array not getting initialized”

estus answer is correct. note that you had 2 different problems there. Try this tutorial, it explains Javascript OOP very clearly. [this video]

Recommends Arijit Datta · 2020-04 · Stack Overflow · on “In JS, ES6, in a Factory, if the property and the param are different, then method is unable to find it”

Why cant the radius be found? It cannot be found because closure is not applicable here. What is closure? - Closure is a concept in Javascript by which local variables & methods defined in a function are available to the child functions. In this case radius is a property of the cir1 object & hence has to be accessed using the this keyword. Research - [this video] Location - 47:50 onwards

Cites GMHLee · 2020-05 · Stack Overflow · on “Are methods within a function object not implicitly linked as a member?”

semi-novice programmer here (on and off with C++ for years, dabbling with C# mostly with Unity) and when creating objects and methods within objects it's to be expected that that method is a member of that object. If I create a new object I can access the function with dot notation object.method. For Javascript it appears that isn't the case? I read somewhere about it being something like a first class object (not sure what that means) and I have to explicitly say that the method is a part of the object. So for example in JS function testObject() { let x = whatever; function testMethod() { } } Is a failure, it will not work. testObject has no idea testMethod is a member. I have to use this.t