0

Sorry, I am still trying to teach myself Javascript and I was wondering whether someone knew the best way to write object oriented Javascript with classes that will interact well with PHP classes.

2
  • 3
    JavaScript doesn't have classes, it uses a prototype-based inheritance model. There are ways of making it simulate more class-based models, but I don't think it's worth the effort. "Object oriented" can be a pretty vague term - is there a specific problem you're trying to solve with classes? Commented Aug 21, 2011 at 23:58
  • @nnnnnn A+ I agree, what is the problem involved that requires classes. Commented Aug 22, 2011 at 2:48

1 Answer 1

1

Javascript is already object oriented, in regards to classes there are many ways in which to achieve "templates". Since you are new to Javascript have a good read of any material from Douglas Crockford especially his book The Good Parts as he will enlighten you to the the true nature of Javascsript.

This leads me to the second part of your question, as to interacting well with PHP, my advice (from experience) is to have a good clear data serialization/deserialization layer from which you interact, JSON will help you immensely. Don't try and be clever, Javascript is a very different language to PHP. Work with the language not against it.

Happy coding :)

Sign up to request clarification or add additional context in comments.

7 Comments

After you read the book, you should study some existing frameworks to consolidate your knowledges.
@dnikku I agree (somewhat), since it is implied that willpots is getting into web development then jQuery (library) is a MUST :)
@martin - I think jQuery is great and I use it a lot, but "a must"? Hardly. There are lots of other options.
@nnnnnn I know there are plenty of other alternatives (many which have evolved more and more like jQuery); however especially for a beginner the sheer size of the community makes it more than worthwhile getting to grips with - but maybe I'm a little biased :)
See, I did it wrong. I learned jQuery to begin with but I am realizing that for some applications, it can be easier to write scratch Javascript. Maybe I'm crazy though :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.