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.
-
3JavaScript 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?nnnnnn– nnnnnn2011-08-21 23:58:40 +00:00Commented Aug 21, 2011 at 23:58
-
@nnnnnn A+ I agree, what is the problem involved that requires classes.martin– martin2011-08-22 02:48:18 +00:00Commented Aug 22, 2011 at 2:48
1 Answer
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 :)