I am trying to do this, I’m a full time front-end dev and am aware that I am yet to achieve this.
When I am referring to OOP skills I am referring to understanding and being familiar with concepts like inheritance, polymorphism, encapsulation, abstraction.
I am aware that it may be more likely to achieve what I’m after by focusing on another language in my spare time. This is the plan, but I’d be really intrigued to hear if anybody has managed to achieve this purely through JavaScript and how you did it.
It’d be even better to hear from strong OOP developers from who use different programming languages to know if they have worked with developers who have managed to achieve this.
Feedback:
Just in case people are wondering where I went from this –
-
I’ve taken a closer look at what
prototypal inheritance means and how
to use it better. -
I’ve decided to spend more time properly
learning ruby (could be any language
that is class based) in my spare
time. -
I’ve decided to experiment (nonchalantly) with different
languages so that I can gain not the
intricacies/exact syntax of them, but
more of an overview of how they
approach OOP. I’ve started with Self, Scheme is next on my list.
Thanks a lot for the really helpful answers.
First, let me preface this by saying JavaScript is one of my favorite languages. I love using it, and I love its power.
JavaScript certainly does OOP, and once you wrap your head around it, it does OOP reasonably well. But I wouldn’t recommend learning OOP via JavaScript for the following reasons:
JavaScript uses a kind of bastardization of Prototypal inheritance and Classical inheritance. In JavaScript, you don’t define classes like you would in a classical language, but there are still remnants of classical inheritance – like the
newkeyword. This is extremely confusing for people who have wrapped their head around classical OOP.JavaScript doesn’t really have a normal concept of private and public variables like a classical language (like Java) does. Sure, you can define public and private variables, but the methods are kind of esoteric. Because JavaScript doesn’t really do public and private variables ‘out of the box,’ the whole idea of data hiding and encapsulation doesn’t naturally apply.
JavaScript can certainly do polymorphism, but it doesn’t do it through regular function overloading/overriding. Instead, a function or method can take a variable number of arguments that can be added on the fly at runtime. Again, it can do polymorphism, it just doesn’t do it like most of the more mainstream and popular languages.
Like I said before, I love JavaScript, and I love working with it. You can certainly do OOP in JavaScript, and you can certainly learn OOP by learning it from JavaScript. But I think that is an uphill battle.
I think you’d be better off learning OOP from Ruby first, then going to JavaScript. Ruby and JavaScript have different syntaxes, but the power and ‘feel’ of the languages are very similar. You can do similar things with both languages, and both languages have similar features and support similar paradigms.