开发者

Has anybody managed to teach themself strong OOP skills through mainly developing with JavaScript? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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 开发者_如何学JAVAwith 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 new keyword. 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.


There's no reason you can't develop strong object-oriented skills via Javascript - but Javascript is a prototype-based object-oriented language, which is quite different from other mainstream object-oriented languages (C++, Java, etc.), which are class-based.

You should familiarize yourself with both models as soon as you can (once you've mastered the basics of javascript), so you can learn from discussions about class-based models without too much friction.

Finally, in case you aren't already familiar with Douglas Crockford, I highly recommend visiting his site, reading his article JavaScript: The World's Most Misunderstood Programming Language, then reading his book Javascript: the Good Parts.


I mainly develop in C# and JavaScript.

Unfortunately I haven't met somebody who has only developed in JavaScript that has strong OOP skills.

It should definitely be possible though. JavaScript has all of the OO concepts baked in. You just have to learn how to use Prototypal inheritence properly to achieve your goals (or learn through a Framework like MooTools, which kind of defeats the purpose).


Many developers argue that JavaScript has no realy OOP functionality and some say you shouldn't even use the OOP functionality that is included. I also coded a lot in JavaScript objectoriented. But I also coded a lot in PHP and Java with all the OOP techniques around.

Important things that missing in JavaScript are static or final classes as well as interfaces. You use them quite frequently in languages such as Java.

I would say that if you only want to learn what OOP means and how it works in small cases, than JavaScript is enough. To really learn OOP im complete, you need to learn a language like Java, C++, Ruby or even PHP.


If you want to learn OOP, but you want an "easy" scripting language to do it in, you would probably be better off working in ActionScript via Flex.


I'm gonna go with "No".

I've worked with several javascript devs, and I could always tell which ones of them where native to JavaScript, and which had a Java/C#/Delphi background

BTW, this is not a dis of javaScript, just an observation.


I suggest you to practice with languages that let you create high level patterns without too much pain... like, why not, Python?

As for Javascript, this post by our Joel is quick to read and goes to the point:

Can Your Programming Language Do This?


Im myself found "JAVA" as the strongest object oriented program i have encountered, i truly recommend it to develop OOP skills.

Good luck mate :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜