Jump to content

Suggestion for Javascript reference


Recommended Posts

This is regarding the reference page...http://www.w3schools.com/jsref/default.aspI suggest you put the word "statement" on this page somewhere. As a newbie, I don't know if statements are a part of JS or not, but in either case the topic should appear on the main reference page. After all this is a school, right? If you want to refer visitors to another page, that's great, but please say something. My understanding is that the following are statements, but it is impossible to tell from the reference pages...counter.number.valuedocument.writedocument.layers.cust.document.writewindow.alertwindow.locationMakes it really frustrating for newcomers. Thanks.

Link to post
Share on other sites

A statement is a combination of expression(s) and/or language constructs.An expression, in the case of JavaScript, is made of objects and operators. W3Schools has reference on both. Language constructs (if, for, etc.) are covered in the tutorial.document.write for example is an object called "write" that is part of the "document" object. Logically, you can find it by first going to the document object, drilling down to the write object, which in this case we see is a method that writes stuff in the source code.Same for all other examples you gave.

Link to post
Share on other sites
A statement is a combination of expression(s) and/or language constructs.An expression, in the case of JavaScript, is made of objects and operators. W3Schools has reference on both. Language constructs (if, for, etc.) are covered in the tutorial.document.write for example is an object called "write" that is part of the "document" object. Logically, you can find it by first going to the document object, drilling down to the write object, which in this case we see is a method that writes stuff in the source code.Same for all other examples you gave.
Link to post
Share on other sites
document.write for example is an object called "write" that is part of the "document" object. Logically, you can find it by first going to the document object, drilling down to the write object, which in this case we see is a method that writes stuff in the source code.
OK, then you are saying the items I listed are objects, not statements, and already appear on the reference pages if I drill down. This helps. Just a minor point, I could not find the followingcounter.anythingdocument.layers.anythingBut thanks for the help. -- Jim
Link to post
Share on other sites

You would need to read the general section on objects for help there. counter is not a built-in JavaScript or HTML object. It is an object a programmer would create independently.The document object does exist, but the layers property has been out of existence for many years now. Kind of like the set up instructions for your electric oven don't mention coal storage.window.location refers to a property of the window object called location. This property is itself an object.window.alert is a method, since it can be made to do something. By itself it is not a statement. It can be integrated into a statement with a few more pieces:window.alert("hello"); // this is an actual statementAdding the parenthesis tells the method to execute. Many methods do not require data to execute, but alert does. That's the quoted material insides the parens. (Not all methods that require data require a quoted string.)

Edited by Deirdre's Dad
Link to post
Share on other sites
I could not find the followingcounter.anythingdocument.layers.anything
There's not a pre-defined object in the DOM called "counter". You could create your own counter object and put properties or methods on it to reference, but it's not built-in. The reason the layers property is not mentioned on the document object reference is because the layers property was a Netscape addition and is not actually part of Javascript, nor is it supposed to be used.
Link to post
Share on other sites

Thank you everybody. I think most of this discussion is about Javascript language constructs (true?). 1) I think I understand these in java script:objects operators putting a property on an objectputting a method on an objectsome properties are deprecated - in order to find current usage, see the reference pages?2) Here is what I would like to find examples for:statementsexpressions how a programmer creates an object independently (create a function?)So here is my second suggestion: How about a page that has examples of these constructs or whatever these notions are called en masse? Sometimes examples are the best way for newcomers to visualize them and learn their names. Thank you! I have another issue or suggestion for w3schools regarding specifying where these things can be used (inside or outside the JS block) that I will start in another thread.

Link to post
Share on other sites

The concepts of statements and expressions are sufficiently broad that it may not be very useful to see examples of them. The only reason is that virtually all of the code you look at in Javascript is either a statement, expression, or both. Here's a for loop, for example:for (i = 0; i < 10; i++)The loop itself could be considered a statement (or, more specifically, a control structure), and there are three expressions inside the loop declaration. In that context, i++ is an expression. You could also have it on its own line:i++;That line is both a statement and an expression, it's a statement with a single expression and nothing else.You can think of an expression as anything that evaluates to a value. That for loop does not evaluate to a value, so it's not an expression. An expression is anything that can go on the right-hand side of an assignment operator (=):var x = <expression>;So, all of these are valid expressions:10i++a + bi > 10 ? true : falseMath.random()window.prompt('enter a value')Some of those are also statements.As far as creating your own objects or classes, creating a single object is as easy as just defining it. These are two ways:

var obj = new Object();obj.property1 = 1;obj.property2 = 2;obj.property3 = 3;obj.method1 = function() { return 'one'; };obj.method2 = function() { return 'two'; };obj.method3 = function() { return 'three'; };

var obj = {  property1: 1,  property2: 2,  property3: 3,  method1: function()  {	return 'one';  },  method2: function()  {	return 'two';  },  method3: function()  {	return 'three';  }};

If you want to define your own class, and then create several objects from it, there are several ways to do that also.http://www.google.com/search?client=opera&...-8&oe=utf-8

Link to post
Share on other sites

The explanation of objects here is pretty thorough, except it does not use anonymous functions to define methods, as jsg shows, and which is quite typical. Maybe that's a good thing for a first tutorial, since anonymous functions tend to confuse beginners.Distinctions between expressions and statements are taking us away from applied technology (web development, ordinary programming, etc) and into the world of computer science. Obviously, programming depends on the existence of computer science, but a programmer does not need to know a lot about computer science to do a lot of good programming. In some cases it helps. I'd say a typical JS programmer would stumble for quite a while before answering that part of your question.IIRC, jsg has a degree in computer science, so he can probably tell you all about voltages, AND gates and other stuff that a typical programmer does not (usually) need to know. Especially a JavaScript programmer.Probably the most useful thing he wrote about expressions was this (not that it wasn't all good):

An expression is anything that can go on the right-hand side of an assignment operator
Knowing that will help you understand certain syntax errors that may show up, if you tried to write something like this, for example:5 = x;oralert("Hello") = "Bye";Specifically, Firefox responds to those with this message: "Error: invalid assignment left-hand side." Other environments might complain about "Illegal L-value," which is basically the same thing: you put the wrong kind of stuff on the left side of the assignment operator. Edited by Deirdre's Dad
Link to post
Share on other sites

Best not lick the battery however. Getting back to the subject, this is a suggestions forum. May I respectfully remind all viewers of my suggestion...

So here is my second suggestion: How about a page that has examples of these constructs or whatever these notions are called en masse?
This thread is very rich in knowledge, but the knowledge belongs in the tutorials, not here, yes? I think most of these constructs could be summarized on a single page and called "Javascript terminology" or something. Let's give other people besides me a fighting chance to understand these concepts.
Link to post
Share on other sites

Well, the suggestion has been made, and eventually the correct people will notice it and take action, one way or another. It may not be clear to you that no one who actively participates on this board is in fact one of the correct people. We're just helping where we can.And anyway, the board archives are very searchable, so in a way, the knowledge belongs here as much as anywhere else.

Link to post
Share on other sites
Best not lick the battery however. Getting back to the subject, this is a suggestions forum. May I respectfully remind all viewers of my suggestion...
So here is my second suggestion: How about a page that has examples of these constructs or whatever these notions are called en masse?
This thread is very rich in knowledge, but the knowledge belongs in the tutorials, not here, yes? I think most of these constructs could be summarized on a single page and called "Javascript terminology" or something. Let's give other people besides me a fighting chance to understand these concepts.
The page Deirdre's Dad linked to covers all of that.Perhaps there's a certain barrier of a mindset here, and we already revealed to you the "secret"... in a way... it's to realize that all "stuff" is chained together in what is commonly reffered to as "expressions", and each expression is basically another expression along with something else. When you see on an actual example something like:
var e = document.getElementsByTagName('div')[0].childNodes[0].innerHTML;

you need to realize that's equivalent to saying

var a = document.getElementsByTagName('div');var b = a[0];var c = b.childNodes;var d = c[0];var e = d.innerHTML;

(examine that one in detail and see if the tutorial or reference miss any of it...)The tutorial doesn't explicitly give this very example or formulation, but it says everything you need to know that will lead you to it. The mindset barrier is created by the fact you never see examples outlined in the way above. The tutorial assumes that you'll gradually build upon it, whereas in order to see something on screen (serving as proof for yourself that you're getting it right), you're leaning towards thinking of chained stuff as one, and "start to run before you can walk".P.S. If you are REALLY interested in the formal syntax of JavaScript, you might be interested in reading the ECMAScript (the official name of JavaScript) specification, and section "5.1" in particular. WARNING: Health risk! Headaches extremely likely.

Link to post
Share on other sites
Perhaps there's a certain barrier of a mindset here,
Now I'm getting really lost. I never asked for a tutorial! I just asked for a page on the w3schools site and did my best to describe the "hole in the donut" as I perceived it. I'll try to be more clear in the future. best -- Jim
Link to post
Share on other sites

Errr.... I'm sorry if you thought that when I say "you" and the mindset thing, I was specifically reffering to you as individual... I was reffering to any JavaScript newcomer. And the rest of my post was mostly about trying to make you understand the deal, after which you can hopefully suggest the best way W3Schools' authors can formulate the tutorial. The way I see it, they've did the best possible thing, with a few necesarry omissions... but if you can persuade us what needs to be changed and (more importantly) how, chances are W3Schools' authors are also going to be persuaded.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...