files with the .js extension

P

Pierre

I have recently bought the book: JavaScript & DHTML Cookbook. As I
opened the .js files with note pad, I asked myself why was the code
formated in such a way. The code looks as if it had been produced by
some kind of programs instead of a person. I also noticed a lot of
little squared zeros; what are those all about?

I have also noticed code formated in a similar way, when viewing some
of the source code of the web pages on the MSN web site. If someone
knows anything about this machine-like formating, I would love to hear
from you.
 
M

Michael Winter

I have recently bought the book: JavaScript & DHTML Cookbook. As I
opened the .js files with note pad, I asked myself why was the code
formated in such a way. The code looks as if it had been produced by
some kind of programs instead of a person. I also noticed a lot of
little squared zeros; what are those all about?

I have also noticed code formated in a similar way, when viewing some
of the source code of the web pages on the MSN web site. If someone
knows anything about this machine-like formating, I would love to hear
from you.

You will usually see this when a text file has been created on another
operating system. Windows, Macs and Unix-based OSs all use different
combinations of two characters to represent new lines. When programs like
notepad don't recognise the combination, they display that character you
see[1].

It's nothing to worry about, but it does make reading difficult.

You could try using a different editor. There are many free ones available
designed for Web development. I use HTML-Kit. If you search the Google
Groups archives, you find that editor recommendations have been asked
frequently in the past. You might want to try some of the ones listed in
those threads.

Mike


[1] The character used, a square (filled or outlined, depending on the
font), is used in Windows to represent non-printable characters.
 
T

Thomas 'PointedEars' Lahn

Pierre said:
I have recently bought the book: JavaScript & DHTML Cookbook. As I
opened the .js files with note pad, I asked myself why was the code
formated in such a way. The code looks as if it had been produced by
some kind of programs instead of a person. I also noticed a lot of
little squared zeros; what are those all about?

The file is likely to have been saved under UNIX, a UNIX derivative
(short: *n*x, e.g. GNU/Linux) or under MacOS (Apple Macintosh).
Those operating systems use different newline delimiters than Windows
(Windows: \r\n; Unix: \n; Mac: \r). Notepad is unable to read the
UNIX and Mac format (thus displayes the "squared zeroes" for those
undisplayable control characters), use an editor that is capable, like
metapad (freeware) or UltraEdit (shareware). If you have installed
Cygwin or have (SSH/Telnet) access to a *n*x system, you can also use
the `unix2dos' program (a `recode' wrapper) on those files.

Another possibility is that the code has been "line-optimized" or
"uglified" (which is bad for a tutorial); you can use a JavaScript
beautifier to make it readable. Ask Google about "JavaScript formatter".


HTH

PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
The file is likely to have been saved under UNIX, a UNIX derivative
(short: *n*x, e.g. GNU/Linux) or under MacOS (Apple Macintosh).
Those operating systems use different newline delimiters than Windows
(Windows: \r\n; Unix: \n; Mac: \r). Notepad is unable to read the
UNIX and Mac format (thus displayes the "squared zeroes" for those
undisplayable control characters), use an editor that is capable, like
metapad (freeware) or UltraEdit (shareware). If you have installed
Cygwin or have (SSH/Telnet) access to a *n*x system, you can also use
the `unix2dos' program (a `recode' wrapper) on those files.

Another possibility is that the code has been "line-optimized" or
"uglified" (which is bad for a tutorial); you can use a JavaScript
beautifier to make it readable. Ask Google about "JavaScript formatter".

In attempting to give a complete explanation, Pointy-Head has again
demonstrated limits of his experience by giving only a partial answer.
A full answer would be encyclopaedic; but an adequate answer would be
more useful.

WordPad - at least in Win98 - transforms both CR & LF endings to CRLF;
given that Notepad is available, WordPad could well be the best
solution.

MiniTrue, for DOS-16, Win32, UNIX, has line-end correction as an example
(and is a very useful tool in general, and so worth fetching, for those
who can operate at the command-line).

The stated conditions for UNIX2DOS are unnecessarily limited; it is
*IIRC* distributed with other software, and one can surely get it over
the Net from FTP archives such as Garbo.

It is better not to fully reformat code provided as an example if there
is any prospect of the associated material referring to it in a layout-
dependent manner,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top