Revision as of 19:10, 4 March 2011 edit72.152.120.17 (talk) →Method toFixed← Previous edit | Revision as of 23:11, 4 March 2011 edit undo72.152.120.17 (talk) →User Machine Elf 1735: new sectionNext edit → | ||
Line 234: | Line 234: | ||
WHERE ARE THE RULES FOR ALL THE LEGAL BUT WIERD CHARACTERS IN IDENTIFIERS? (e.g. "$", "_", etc) <span style="font-size: smaller;" class="autosigned">—Preceding ] comment added by ] (]) 16:29, 16 September 2010 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot--> {{small|''(])''}} | WHERE ARE THE RULES FOR ALL THE LEGAL BUT WIERD CHARACTERS IN IDENTIFIERS? (e.g. "$", "_", etc) <span style="font-size: smaller;" class="autosigned">—Preceding ] comment added by ] (]) 16:29, 16 September 2010 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot--> {{small|''(])''}} | ||
:Added to ]: "An identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). Starting with JavaScript 1.5, you can use ] or ] letters (or \uXXXX Unicode escape sequences) in identifiers."—] (]) 00:18, 17 September 2010 (UTC) | :Added to ]: "An identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). Starting with JavaScript 1.5, you can use ] or ] letters (or \uXXXX Unicode escape sequences) in identifiers."—] (]) 00:18, 17 September 2010 (UTC) | ||
== User Machine Elf 1735 == | |||
User:Machine Elf 1735 keeps reverting my edits and reverting my reverts. He has put in blatantly untrue information into this article, such as true == "0", "Only ±0 and NaN are false Numbers. ", and "Only the empty String is false." when in fact, 3 is not equal to true, and NaN is not equal to false. There is a difference between falsy and false values in javascript, but he removed this note. He even put a tenary operator into an example on equality, which is completely unrelated. Then he goes on my talk page accusing me of "putting incorrect information" in. He also just deletes my message from his talk page and links to ]. I request he be blocked for reverting correct editing, putting in untrue information, and deleting talk messages about the issue, and etc. ] (]) 23:11, 4 March 2011 (UTC) |
Revision as of 23:11, 4 March 2011
Tip: #section links are case-sensitive on most browsers
Links from this article with broken #section links : |
This is the talk page for discussing improvements to the JavaScript syntax article. This is not a forum for general discussion of the article's subject. |
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
Inaccuracy (needs citation)
The following statement: "else statements must be cuddled (i.e. "} else {" , all on the same line), or else some browsers may not parse them correctly." found in section 5.1 is incorrect. I have been programming in javascript for 4 years, and have never used that programming style. I have yet to notice any browser incompatibilities. If this statement is true, please provide a citation. - Kickboy 04:07, 24 August 2006 (UTC)
Inheritance without prototyping, etc.
I removed that part because it isn't syntax, it isn't very useful or common in modern times, et cetera. That and the preceding section need some clarification, as it is long and some ground is covered multiple times, but I'm not up to that right now. Quamaretto 03:19, 20 February 2006 (UTC)
Biased views
I am a bit surprised about Quamaretto's behavior. He tends to throw away contributions that dont fit into his view of JavaScript. I am currently unsure if I should waste my time contributing to WikiPedia if it is so easy for others to impose their biased view upon others.
- As far as the most relevant sources are concerned, you were apparently right about the origin of the syntax regarding Java and other languages, and I left the original quote in the article. (The first time I removed your material, I assumed that you were trolling or didn't have a relevant source since you didn't present one. That change is my bad, I guess.)
- As far as the other material, you should see the article WP:NOR and others in WP:What Misplaced Pages is not. There are sound reasons for all of those. The language comparison section is original material you wrote to demonstrate your point—, which was plainly already demonstrated by the quote.
- Basically, I corrected your changes to present the relevant information you gave, as well as to preserve the stated rules of Misplaced Pages. There's no reason to get upset over that. Quamaretto 00:02, 28 April 2006 (UTC)
- Look at the large amounts of example code in the sections below. For example the assignment section. Is it really a good idea to present tons of scarcely commented examples to the reader ? Is it allowed to confront users with vast amounts of example code, but not allowed to explain to them that assignment and operators were taken over from C with almost no change ? Before presenting lots of boring examples, I wanted to give the reader a rough orientation scheme about what to expect.
- The second reason for listing up the origins of the syntax elements was to introduce the reader to the subject of JavaScript syntax. There was none.
- Another observation which leaves me speechless is that my introduction gets thrown away, while other commercial artifacts are kept. Look at the third paragraph of the JavaScript page. Look at the two links at the end of the paragraph. Link 2 may be justified (Sun Trademarks), but link 1 points to an unrelated Copyright page at SAP. This looks like commercial subversion to me. But maybe I just didnt understand the deeper meaning. Therefore, I left it unchanged because I thought I might have misunderstood it.
- It is much easier to throw away contributions of others than to first try understand what they wrote. That's why WikiPedia is not ready to rival other valuable sources of information.
- I don't know why the SAP link was included, other than that it repeats the claim on the Sun page. It isn't exactly a prominent place for advertising, so that isn't a likely motive.
- Regarding with code with few comments, the goal is to write accurate encyclopedic material. Providing an easy introduction to the language is not. Yes, this page is a mess and needs improvement, but it was worse in the past.
- On the introduction you wrote, see "Original Thought" above. There are rules; follow them and people won't revert your changes.
- Anyway, don't think people are going to revert anything you write here. If you write anything else, I'll defer unless it's very clearly out of bounds. It would be helpful if you wrote a qualifying opening paragraph, or several, summarizing the features of the syntax. Pay attention to the guidelines and no one will probably bother you. Quamaretto 22:23, 28 April 2006 (UTC)
Missing Syntax Structures
This article could stand to mention function literals, regex literals, and possibly object prototyping. 08:10, 16 August 2006 (UTC)
The article is also lacking a discussion of the with() construct. (Not sure if it qualifies as a operator or a syntax, I think technically it is an operator).
How about additional uses of ()
? Such as this syntax common with frameworks these days: (function() { ... })();
Ziemkowski 17:20, 12 September 2007 (UTC)
with()
is a statement for changing scope chain. I don't know whether it can be counted a control structure.()
is function call operator.()
after a function is only a function call syntax.(function() { ... })();
only is function expression syntax and function call syntax using together.--LungZeno (talk) 22:45, 27 January 2009 (UTC)
Good Job
This was a great article for someone in need of a quick reference on the specific differences between JavaScript syntax and the syntax of languages like Java and C++ for someone with experience in those languages and working on a small project in JavaScript.
Yes, thanks a lot to the author(s). Short and to the point. —Preceding unsigned comment added by 84.167.27.253 (talk) 19:02, 29 May 2008 (UTC)
Miscellaneous and reserved words
I think the Miscellaneous section could stand to be rewritten, and possibly re-titled to Parsing or something. We don't really need a level three head for the simple sentence "JavaScript is case sensitive." Also, JavaScript's reserved words should be added to the article. 209.92.136.131 21:37, 12 December 2006 (UTC)
Various
Variables : It says : "Variables in standard JavaScript have no type attached, and any value can be stored in any variable.". But when a value is assigned to a variable, its type is recorded - i.e. attached. Something like "A variable in standard JavaScript has no fixed type, and any type of value can be stored in any variable." perhaps? The value 0.1 cannot be stored exactly as a Number, so "any value" might mislead.
Suggest rephrasing (too convoluted?): Variables are variant types that can take any value of a small number of types , and which are converted or changed implicitly as needed. In effect, any value can be stored in any variable.
footnote#1: Number, String, Object, Boolean. Functions are Objects, and so can also be stored in variables]
Variables (2): It says: "... variables used without being declared with 'var', are global (can be used by the entire program)."
This needs clarification: Variables declared in a function do have global scope, but are not defined until the function has been evaluated, and a function cannot be evaluated -- at global scope -- until it has been declared.
In effect, one must declare before use.
Re the example code: Any use of "twenty" causes ReferenceError until f has been declared, and called at least once.
Note that functions declared inside function scope can be called inside that scope before the source text appears. Again, variables declared without var in inner functions are not usable until the function is called.
- Actually, it is a little more complicated that the above paragraph would represent. A variable simply used inside a function without specifying a scope MIGHT be global, but the javascript parser is supposed to start at the bottom of the execution context chain (i.e. the function in which the statement resides), and then iteratively search for a scope higher in the chain. So if you have nested functions, it is possible to use a variable without instantiating it with var but not be available globally, if there is an outer function in which that variable is defined. This is one of the concepts that make closures in JavaScript possible.24.49.69.72 17:50, 7 April 2007 (UTC)
Numbers : It says "... they do not always exactly represent decimal numbers, particularly fractions.". They can represent all integers up to 2 exactly. So "... they do not usually represent decimal fractions exactly."?
Strings : The character set is not presently mentioned - put "sequence of UniCode characters"? A third example might illustrate ' within "...", \t \n, \u03A3 for example. In MSIE6, and as I recall in ECMA-262, strings CANNOT be indexed as arrays.
Arithmetic : Plus is also a unary operator. It is useful for converting String (or Boolean) to Number : Count = +MyForm.Ctrl.value .
Comma : I see no mention of it. No example of a var list, nothing to support for (J=0, K=1 ; K<4 ; K++) {} which I hope is legal.
82.163.24.100 16:56, 31 January 2007 (UTC)
I see no mention of continue break label in connection with loops. 82.163.24.100 13:36, 29 October 2007 (UTC)
Multidimensional Arrays
This is really nice, but I think it would be good to have one paragraph on multidimensional arrays and some examples of declaring and using them since (at least for 2 dimensions) this is a very common usage. —Preceding unsigned comment added by 167.1.146.100 (talk) 12:59, 8 February 2008 (UTC)
"Modern Day" Prototyping
All major standards compliance browsers support __proto__ object in Elements, as well as __defineGetter__ and __defineSetter__. Perhaps this should be incorporated into the document? —Preceding unsigned comment added by Yhulkdsfdd (talk • contribs) 17:44, 11 September 2008 (UTC)
- Since it's hard to determine what's in JavaScript or not because of the lack of a spec delineating differences from ECMAScript, I'm not sure we should mention __proto__, __defineGetter__, and __defineSetter__. --Maian (talk) 21:34, 11 September 2008 (UTC)
If ... else
Should it not be explained that the following:
if(x==1){ something() } else if(x==2){ somethingelse(); }
the else if works like a shorthand if (without {})
if(x==1) do something here so really it is if(x==1){ something() } else{ if(x==2){ somethingelse(); } }
Sorry if that didn't make sense, I find it hard to explain.
Bitwise
This needs to be explained. As the rest of the article explains everything in adequate detail, this is more like a list.
FAQ references changing
Sections of the CLJ FAQ are being reordered and convered from numeric anchors to textual ones. When that is finished, Wiki should be searched for such references to be corrected. I have updated the two in this Article. 82.163.24.100 (talk) 18:34, 12 October 2008 (UTC)
For loop: end-condition?
for (initial;end-condition;loop statement) { /* statements will be executed every time the for{} loop cycles, until the ending condition is satisfied */ }
The condition should be called while-condition, or just condition, but never end-condition. As in every C-like language, the for{} loop cycles while the condition is satisfied. --Como (talk) 14:28, 23 October 2008 (UTC)
No response in several months... I assume everyone agrees, so I dared to change the article. --Como (talk) 09:26, 3 March 2009 (UTC)
Reworked Methods and Inheritance
Much of what is written about this on the web is wrong or misleading or too tangled up in browser semantics to be intelligable. So I have added succinct, non-trivial examples that highlight the issues. I learnt a bit in the process. All examples have been tested.
I hope others find this useful, particularly those comming from other OO languages that are quite different.
The article should probably be renamed to something like JavaScript Language rather than Syntax. Syntax without semantics is useless. But I think the contents is quite good at the moment -- a short sharp overview.
The JavaScript Prototypeing logic is quite bizzar IMHO. Classical Lisp IS-A links would be fine. But in JavaScript it is confused by C++ thinking. MyFunction.prototype is plain wrong -- it should simply be this.prototype = parent. No need for magic. Tuntable (talk) 07:47, 3 February 2009 (UTC)
For...In and Arrays: useable together or not?
The article states that For...In is not useable with arrays, but the W3Schools website gives arrays as an example of the use of For...In: http://www.w3schools.com/js/js_loop_for_in.asp and the Microsoft Developer Network specifically states that For...In can be used for "stepping through ... all the elements of an array", without giving any warning about unexpected results. (This is referring to JScript, rather than JavaScript, admittedly, and I don't understand the relationship between the two.) http://msdn.microsoft.com/en-us/library/kw1tezhk(VS.85).aspx FrankSier (talk) 15:44, 6 February 2009 (UTC)
- I have done some research on this subject - not original research :) - and modified the article mainly by putting in some inline references. FrankSier (talk) 21:37, 7 February 2009 (UTC)
Method toFixed
Method toFixed should not be recommended for the web because it is unreliable in MS IE 7 and I think all previous versions of IE that had it - 0.07.toFixed(1) gives 0.0. The algorithm for StrU currently in http://www.merlyn.demon.co.uk/js-rndg1.htm#GC has no known errors. 82.163.24.100 (talk) 18:44, 3 April 2009 (UTC)
Internet explorer uses JScript, not JavaScript, it works with all JavaScript browsers. 72.152.120.17 (talk) 19:10, 4 March 2011 (UTC)
alert vs. println
Is there a reason that println is used in the examples instead of alert? I like JavaScript on client and server, and code in it everyday (helps pay the bills), but I _wouldn't_ be coding in JavaScript if it wasn't for the ubiquitous web browser. Given JavaScript was invented as a browser scripting Language, would anyone be opposed to me swapping out println and replacing it with alert? I would also change the note at the top of the page noting how alert assumes any user who cuts and pastes the examples will be working in a browser. Jeremywosborne (talk) 21:02, 15 April 2009 (UTC)
Replaced 'println' reference with 'alert' function calls, along with reasoning for using 'alert.' Jeremywosborne (talk) 01:43, 22 April 2009 (UTC)
- I was the one that replaced all the document.write/alert references with println. To me, JavaScript is just a language that just happens to be used most often on the web. I was trying to keep the article as specific to the language as possible, without complicating it with the DOM, which is NOT part of JavaScript. But I'm happy enough as long as there is a note explaining that document.write/alert is not part of JavaScript and is only used because the browser is the most common host of JavaScript. --Maian (talk) 07:50, 22 April 2009 (UTC)
- Thanks for the response Maian. It's very difficult to create demonstrable JavaScript examples with the lack of a standard output function. After so many hours coding in this sometimes great, sometimes atrocious language, I figured I'd err on the side of making things browser compliant. Jeremywosborne (talk) 20:09, 22 April 2009 (UTC)
Functions
The code could be changed to also illustrate the ternary operator ? : :
return diff > 0 ? gcd(segmentB, diff) : gcd(segmentA, -diff)
Since the code might be copied, it would be well to change it, after testing, to the more efficient method, in which the second argument to the internal gcd is either A mod B or B mod A, which is approximately equally easy to read; or to the wondrous non-recursive form :
function GCD(U, V) { // or HCF while (true) { if (!(U %= V)) return V if (!(V %= U)) return U } }
And, for the same reason, the alternative acronym HCF should be included. 82.163.24.100 (talk) 20:01, 24 July 2009 (UTC)
Native Objects
I have completed the list of Native Objects by reference to the Standard.
The page should not be allowed to get too long, and giving much detail on Native Objects would use a lot of space. How about a new page for JavaScript Objects, with the entries on the Syntax page being condensed to about the size of the first paragraph about Arrays? 82.163.24.100 (talk) 11:51, 26 July 2009 (UTC)
Add Description of the Math Object
This is my first contribution to Misplaced Pages anywhere. (-: So be kind to me! :-)
I have to own up to being a newby at JavaScript too though I have been in computing since the 1960s.
I would be grateful for any suggestions or comments about my attempt to insert a description of the Math object. The place where this appears (5.4) seems to need no more than this description does it? Perhaps there should be more elsewhere about doing arithmetic. E.G. There is no discussion of operator precedence.
Is the example at the end too complicated? I wanted to get several different methods into the same line of code. - Wogga62 22:55, 15 September 2009 (UTC) —Preceding unsigned comment added by Wogga62 (talk • contribs)
- Well, first of all, I don't really like how this article is shoehorning the JavaScript API into an article about JavaScript syntax. I'd much prefer all that stuff moved to the wikibook.
- With that said, I do like the table. It could use links in the description column, e.g. e (mathematical constant) (BTW, it's Euler's number not Euler's constant). And the example and the link to w3schools at the bottom is unnecessary.
Constructors and Object Creation
The text claims that the constructor function called when instantiating an object (i.e., the function referenced from a "new" expression) is "not remembered." That is false in all major browsers: the "constructor" property of every object contains a reference to the constructor function. (Pointym5 (talk) 16:34, 29 December 2009 (UTC))
The fact that the constructor parameter list is optional in a "new" expression is not discussed. (Pointym5 (talk) 16:41, 29 December 2009 (UTC))
Characters allowed in identifiers
WHERE ARE THE RULES FOR ALL THE LEGAL BUT WIERD CHARACTERS IN IDENTIFIERS? (e.g. "$", "_", etc) —Preceding unsigned comment added by 24.129.93.200 (talk) 16:29, 16 September 2010 (UTC) (moved to new section)
- Added to JavaScript_syntax#Variables: "An identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). Starting with JavaScript 1.5, you can use ISO 8859-1 or Unicode letters (or \uXXXX Unicode escape sequences) in identifiers."—Machine Elf 1735 (talk) 00:18, 17 September 2010 (UTC)
User Machine Elf 1735
User:Machine Elf 1735 keeps reverting my edits and reverting my reverts. He has put in blatantly untrue information into this article, such as true == "0", "Only ±0 and NaN are false Numbers. ", and "Only the empty String is false." when in fact, 3 is not equal to true, and NaN is not equal to false. There is a difference between falsy and false values in javascript, but he removed this note. He even put a tenary operator into an example on equality, which is completely unrelated. Then he goes on my talk page accusing me of "putting incorrect information" in. He also just deletes my message from his talk page and links to Misplaced Pages:MAJORDICK. I request he be blocked for reverting correct editing, putting in untrue information, and deleting talk messages about the issue, and etc. 72.152.120.17 (talk) 23:11, 4 March 2011 (UTC)