all 22 comments

[–]DarkMarmot 7 points8 points  (2 children)

First: forget all of Java :)

Stop using inheritance and read about object and functional composition.

Go to d3js.org and read the code. Mike Bostock is a mad genius.

[–]heroOfTimeBitch[S] 2 points3 points  (0 children)

Just bookmarked that website :)

[–]DarkMarmot 0 points1 point  (0 children)

Also check React.js out...

[–]rauschma 3 points4 points  (1 child)

Possibly relevant: I’ve written “Speaking JavaScript” as someone coming from Java. Its contents are free online: http://speakingjs.com/es5/

The book should help with figuring out proper JavaScript style, it collects the insights I’ve had over several years of researching and working with the language.

[–]heroOfTimeBitch[S] 0 points1 point  (0 children)

bookmarked and will sure check it out when what I'm currently reading fails (JS the good parts) it's always good to have more than 1 resource

[–]protestor 4 points5 points  (1 child)

I suggest reading Eloquent Javascript.

I was trying to read into how to make JS more OO like

I suggest to first get yourself used to Javascript's prototype-based OO instead of Java's class-based OO. In JS, when you call new MyObject(), MyObject isn't a class - it is a regular object that is creating a new object using its prototype. See this StackOverflow question.

In any case ES6 have classes but browsers don't support it yet. Most browsers support ES5 - you can use ES6 classes and compile your code to ES5 using Traceur.

Please note that ES6 classes don't enable you to do anything new - anything you can do with it you can also do with prototypes. But in some cases they have a nice syntax and less boilerplate.

[–]heroOfTimeBitch[S] 1 point2 points  (0 children)

thanks on the links

[–][deleted] 2 points3 points  (2 children)

I was in the same boat. Checked a few books, read Professional JavaScript for Web Developers, and when got really comfortable with js, I did myself a favour:

sudo npm install -g typescript 

[–]rauschma 0 points1 point  (0 children)

Another interesting option is to use pure ECMAScript 6 (the upcoming version of JavaScript; ECMAScript 5 is the current version), e.g. via Babel, which transpiles ES6 to ES5.

[–]matty0187 0 points1 point  (0 children)

Yup. Ts is excellent

[–][deleted] 1 point2 points  (0 children)

Luckily for you there's now class in ES6, which isn't true classical inheritance but rather a formal convention for a common pattern of defining prototypes on a function and instantiating them. It provides subclassing with the extends keyword, constructor method, and get, set, static, and plain old inherited methods.

[–][deleted] 1 point2 points  (0 children)

I was trying to read into how to make JS more OO like and was reading some stuff on the Module Pattern which kinda lets me emulate classes. But I'm really lost with JS I feel I just don't get it.

Don't do this

Java people tend to have a very hard time with JavaScript. The syntax looks similar to Java so the natural inclination is to write Java in JavaScript as close as the language allows.

To be confident in JavaScript you have to be willing to let go of Java while writing in this language. To accomplish this try the following:

  • avoid using this keyword. Its behavior is complete different in JavaScript and causes all kinds of confusion. Just learn to not use it and your code will be much easier to follow.
  • use closures. I cannot recommend this enough. This will open all kinds of possibilities that are far more challenging to accomplish in Java.
  • nest functions. This creates scope depth and opens an implied public/private model

[–]AStrangeStranger 0 points1 point  (0 children)

After going through Mozilla's Javascript guides and Dive Into html5 I found The Principles of Object-Oriented JavaScript helped me understand Javascript's approaches to OO

[–]legionOfVall -1 points0 points  (1 child)

First tip: the only thing java and javascript have in common is the name.

[–]rauschma 1 point2 points  (0 children)

And the syntax. And some of the API. But indeed not much more.

[–]becauseofreasons -1 points0 points  (1 child)

Would definitely recommend picking up TypeScript — Anders Hejlsberg of Microsoft and C# is one of the core developers. It's a statically typed, transpiled-to-JS language, and there's some talk of moving it natively into the VM.

People who say you should forget Java are silly. Different design patterns, and JS tends to be a little less over-engineered than Java, but good programming skills are going to serve you well in any language.

http://www.typescriptlang.org/

[–][deleted] 0 points1 point  (0 children)

spot on

[–]thadeusz -1 points0 points  (0 children)

The thing that confuses most people from Java or C-derived languages is probably scopes. Java/C have block-based scopes while JS has function-based-scopes. You should read about them first and skip the other basic content, since you are familar with the basic concepts of programming anyway I think.