Helmut Giese wrote:[color=blue]
> Hello out there,
> I am a rather experienced C programmer. However, today I got a
> javascript assignment because someone left (something like: "You're a
> great programmer - you'll handle this.") and I never have done any web
> stuff before. Oh, and it's due within 2 weeks of course :(
>
> Having had a first look at javascript I noted some familiarities with
> C, but there also seems to be a lot of pre-defined stuff (like
> 'document') with certain properties / functions, which is a bit
> confusing.[/color]
Brother , I feel for you. A new language can be a challenge.
Being a fellow "C++" programmer (~20 years) though,
I can tell you that while javascript is certainly not "C++"
it will work fairly nicely with your knowledge of "C/C++"
once you get the hang of it.
Since the most common context for javascript is the browser,
the line between the language , and the HTML page (think DOM)
it acts upon is fairly fuzzy, but the document object is part of
the DOM (Document Object Model).
But as I was saying , javascript and DOM are pretty well joined at
the hip.
[color=blue]
> I have listed some basic questions below and I am hoping someone will
> be able to provide some links ot other information answering those.
>
> 1) What is the current version of javascript which is supported by the
> current browsers (or is this a no-issue)?[/color]
This is not the way to look at javascript at all.
Each browser's instance of javascript in each version of
that broweser can and often do have differences, but the LAST and I do
mean LAST thing you want to start doing is thinking in version numbers.
Two nifty features of javascript help you avoid version numbers.
1.) You can ammend almost any javascript object , including
most of the base objects to include any methods/variables or other
objects you dream up. This can be done per instance , or per baseclass
via the "prototype" keyword, which can be used to create derrived
classes or to augment existing base classes.
2.) The second feature that helps javascript be sorta versionless
is that conditionals like if() for() etc don't mind at all if you say
if(document.thisniftyfunction) to test for a feature.
Now you can say if(!document.functionIwaslookingfor)
document.functionIwaslookingfor = simulatedfunctionality
I call this object detection and normalization (patching)
You do it by the object , not by browser or version.
[color=blue]
> 2) A reference of pre-defined objects and their properties /
> functions.[/color]
There are a boatload of sites out there. You could go look in the
javascript section of my site (link in sigline) and I have in
my ancient javascript section a dynamic object map (way old) , but
it's a good place to start. There is also function documentation
with examples , so you can browse a list of common functions.
[color=blue]
> 3) How do you debug javascript? If you make an error, wrong HTML might
> show up (this could give you a clue) but also nothing might show up at
> all - what do you do then? Stare at the code?[/color]
Typically on the [tools] or other menu in the browser is "javascript
console" or something similar that will tell you the errors.
Typically I develop in Firefox as it gives better error messages
than IE. Although the IE browser is running at the same time to make
sure the code works there too. There are also javascript debuggers
that run in the browser. They are sorta neat , but I get much more use
out of the plain old javascript console
[color=blue]
> 4) Libraries / collection of often used functions (handling of strings
> and dates, numeric stuff, etc.)[/color]
Javascript has many classes, which you can even subclass , including
String()
Date()
Math()
[color=blue]
> 5) A side note: Is it possible in javascript to create variable names
> at runtime and access them? Something like (e.g. iterating over input
> fields)
> for (i=0; i< 10; ++i) {
> currField = <construct name of input field i here, e.g. inp0>
> currField.value = ...
> }[/color]
Most cetainly. You can add just about as many objects methods or
variables as you like to just about any object onthefly.
Just make sure the object your adding things to exists.
OK
ExistingObject.ExistingObject.Newthing="whatever"
ERROR
ExistingObject.Newthing.Newthing="whatever"
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<>
http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<>
http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.