Jump to content

Simple Js Syntax Question - Why Does This Work?


doug
 Share

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?
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...