Jump to content

Simple Js Syntax Question - Why Does This Work?


doug

Recommended Posts

I've been using JavaScript, both client-side and server-side, for years. I never noticed this before though. Here is a quick client-side example:

<html><script>var a = new Object();a. b = 'testing';document.write(a.b);</script></html>

The above page opens and runs without complaint in at least Safari and FireFox. The equivalent in my server-side JS also compiles without error and runs fine.But... notice the extra space after the period, before the property name, in the a. b = 'testing'; line. Why doesn't that space cause a problem?Just curious.doug

Link to comment
Share on other sites

That seems strange to me, maybe the browsers are forgiving about that aspect.I haven't heard of server-side Javascript before, how does it work?

Link to comment
Share on other sites

That seems strange to me, maybe the browsers are forgiving about that aspect.I haven't heard of server-side Javascript before, how does it work?
There is no one server-side JavaScript, but the basic idea is that it is the same language, with all the core JavaScript methods and properties: String, Date, Objects, prototyping, etc. In our case, it interacts with a native object-oriented server-side database so you can use extended methods to do things like create new users, new discussions and folders and other kinds of objects for storing in the database.Naturally server-side JS is not aware of the client, so, for example, there is no "document" object to work with. Similarly client-side JS is not aware of the server-side database.The server-side JS can dynamically generate web pages, similar to how PHP does it. And the generated pages might have client-side JS in them.It's an alternative to PHP in some sense. I prefer it to PHP because JavaScript is such a rich, flexible language and you don't have to deal with two languages for development. But unfortunately it is not standard at all, or that wide spread.But in our system it works very well. It's also compiled on the server side so it's very fast.doug
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...