Jump to content

info for a learner.......


dgabrahams

Recommended Posts

I am still getting to grips with Javascript and need some help.........I have gathered that if I use a 'var' I can call it whatever I want. There are however reserved words which seems to be a very small list that I have found in the back of a book I am learning from........My problem is things such as 'getElementById' I would consider in my layman terms a reserved word, and many scripts I try and read have these kind of things and many I have never heard of...............another example script being the use of 'element.up' or 'element.down' - my problem is I still have no way of telling what words (such as up or down) javascript will understand and do something with.........so down to my question.............is there a reasonably comprehensive list anywhere on the internet where I can see these words with a description of what they do?I use W3Schools but for my learning but really need some nice long lists of the things javascript can do so I can get down to doing them myself...........Much obliged for any help!

Link to comment
Share on other sites

getElementById and the like aren't reserved... you can override them if you want. It's just that if you do, you'll get the thing you set afterwards, not the thing the browser provided for you.You can do for example:

var setTimeout = 4;

but if you want to actually use the setTimeout function, you'll have to use

window.setTimeout

and even THAT is not reserved... you could do:

window.setTimeout = 4;

and both setTimeout and window.setTimeout will have the value 4.A detailed list of JavaScript objects is available at the W3Schools JavaScript reference, but keep in mind each browser has its own additional functions and objects.

Link to comment
Share on other sites

getElementById and the like aren't reserved... you can override them if you want. It's just that if you do, you'll get the thing you set afterwards, not the thing the browser provided for you.You can do for example:
var setTimeout = 4;

but if you want to actually use the setTimeout function, you'll have to use

window.setTimeout

and even THAT is not reserved... you could do:

window.setTimeout = 4;

and both setTimeout and window.setTimeout will have the value 4.A detailed list of JavaScript objects is available at the W3Schools JavaScript reference, but keep in mind each browser has its own additional functions and objects.

thanks some very useful info!I have looked again at the W3C pages, where do they list the .up and .down stuff?
Link to comment
Share on other sites

There are reserved words and then there are other words that Javascript understands, such as length, up, down etcI need to know where to find these, I have already found the reserved words - I simply call them such as they are similar to reserved words but not exactly.......

Link to comment
Share on other sites

As long as you don't explicitly add properties to the document object or any element objects, the only object you really need to worry about is the window object. When you create a global variable or function, these are attached to the window object. SO if you add the properties and methods of the window object to your list (and anything that is referred to as a global property or method) you should be fine. Also add to that the list of built-in object prototypes:ArrayBooleanDateMathNumberStringRegExpAll of these are also children of the window object. Defining anything in the global space with those identifiers will overwrite the objects and they will no longer be available, so you want to avoid that, as you suspect.Defining a var-type variable inside a function with a global identifier will create a local object with the same name, but the global objects should still be accessible by prepending the name of window object. Thus:

function test() {	var Date = 5;	var d = new window.Date();	alert([Date, d.toString()]);}test(); // "5,Sat Feb 19 2011 13:31:17 GMT-0700 (MST)"

Link to comment
Share on other sites

The term is "predefined".Note that those are W3Schools pages, not W3C pages. W3Shools is not related to W3C.By the ".up" and ".down" do you by any chance mean "onkeyup" and the like? They're in the Events page on the reference.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...