Talk:JavaScript

About

 * Started: 18 September 2005
 * Size: 8,200 words (Sep 2008)

DOM Manipulation features
It would be nice to have a list of DOM Features, with exsamples. I'd like to see what can and what can not be modified in a page on the browser side. Ervinn 22:33, 5 July 2006 (UTC)


 * Sitepoint are working on that and now have a JavaScript reference section which covers the DOM Pmw57 (talk) 03:56, 21 February 2009 (UTC)


 * The JavaScript Wiki, which I administrate, has the beginnings of such a reference for both DOM and ordinary JavaScript types, along with useful templates for such content. The top-level category is here. --Jesdisciple (talk) 08:27, 11 May 2010 (UTC)

files
I use  in a form to load a file. Normally, the user clicks it to load a file, and when the form is submitted, the file gets sent directly to the server.

Is there any way for JavaScript to read some of that file? (Perhaps something similar to the way JavaScript can read a file on the server using Programming Ajax?) So JavaScript code can check to see if it's the right sort of file (validate)? That way JavaScript could immediately tell the user to pick some other file (or cancel), rather than waiting until that file is sent to the server and rejected there.

(Is there a better place to post this kind of question? Perhaps http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference/reorg ?) --DavidCary 04:01, 30 January 2007 (UTC)
 * That would be a security issue. And this wikibook doesn't get much exposure and is largely inactive, so, yes, I'd advise searching for better communities to consult. --68.94.206.90 21:14, 25 November 2007 (UTC)


 * How is this a security issue? The section of the book that discusses this -- JavaScript/Working With Files -- currently doesn't mention any security issues; should it? --DavidCary (discuss • contribs) 12:35, 8 September 2011 (UTC)

Table of Contents
I'm new at this, so I apologize if I did this wrong. The table of contents looked pretty incomplete, had some headings that I found confusing, and had a couple of things that looked like they needed to be restructured. So I just went ahead and changed what I thought needed to be changed.

I added a ton of blank new sections. I'm planning on starting to fill some of these in, but I would love to see other JavaScript programmers tackle some of them if anyone gets the inclination.

--Wanorris 9 March 2007


 * Thank you Wanorris for helping to structure things here - I'm going through some sections now performing many much needed tidyups. Pmw57 (talk) 09:11, 21 February 2009 (UTC)

Contributers page
Made the page to sign if going to contribute Extreme circuitz 00:41, 1 October 2007 (UTC)

Is anyone going to do any work on this book?
I would like to propose some changes.

I think JavaScript should be regarded as a language in its own right, not just an appendage to a web browser. This means that the emphasis in the JavaScript book should be on JavaScript and how to write it well rather than on the application of JavaScript to web pages. Detailed discussions of web page document object models belong elsewhere and anyway the DOM is a sufficiently complex subject to need a book of its own. I don't mean that the DOM must not be mentioned but that it is not dependent on JavaScript nor is JavaScript dependent on it. For instance my interest in JavaScript just now is in programming inside Open Office, hence discussion of a web page DOM is irrelevant to me just now. Of course example code would frequently use the DOM but the details of the DOM should be given in a separate book linked to this one. Anyway I might contribute a chapter or two regardless of the organization. --kwhitefoot 17:38, 27 November 2007 (UTC)


 * Ooh... I didn't know this was here.  In case anyone's still around, we have a load of relevant content at the JavaScript Tutorial.  That wiki also has several general articles, and it's all licensed under the GFDL. --Jesdisciple (talk) 04:47, 2 November 2008 (UTC)

names of pages in this book
You can set up any hierarchy you want on the JavaScript/Contents page. But to make that easy to shuffle around and improve, the actual pages in this book should be named with the standard "flat" Naming policy: "JavaScript/" at the beginning, followed by a chapter name -- a self-descriptive chapter name like "Bookmarklets", not a uninformative "Chapter 17". (Older names such as "Programming:JavaScript:Standards and Best Practices" will eventually be converted to new-style names like "JavaScript/Best Practices"). (If they all were old-style, then I would leave it alone -- but most of them are already new-style today). Also, all pages of this book should have the " " label stuck on somewhere, so they will be automatically listed at Category:Javascript. --DavidCary 07:02, 5 December 2007 (UTC)

Cover image

 * See also JavaScript/Cover.

I have removed the image shown here in the thumb from the main page. IMHO the text "great book" is pretentious. Also, the image overcrowded the top of the page, forcing the readers to scroll down to the table of contents. A book about JavaScript would hardly have a landscape format--another downside.

--Dan Polansky (talk) 09:28, 7 September 2008 (UTC)

Program flow
What was supposed to be the content in the "program flow" section? The two options I know of either describe how JavaScript executed (e.g. executed in order from top of HTML file) or having to do with control loops (for, while, etc.) - and I think that both of these are already covered. --Sigma 7 (talk) 23:07, 6 February 2009 (UTC)


 * Since there wasn't any objection or comments, I removed that section from the draft version. --Sigma 7 (talk) 19:57, 22 February 2009 (UTC)

Purpose of this book
Is this book intended as a tutorial, or as a reference? At the moment it is neither. If the first, we will need to add a couple of exercises to each chapter, and much more explanation. If the latter, we will need to describe all reserved words in detail, as well as all functions.

For the moment i have assumed both. I have started creating small exercises. One additobnal problem we will have to solve is how to supply the answers as downloads: zips are not among the allowed filetypes here.

TeunSpaans (talk) 17:14, 12 May 2009 (UTC)


 * As the limitations here prevent delivery of top quality exercises and answers, i will stop working on this book. Sorry TeunSpaans (talk) 20:13, 15 May 2009 (UTC).

Request for Community Review
I'm revising the contents of some pages and removing others from the primary tutorial altogether. As this is a fairly sweeping change, I want to get community review before making it. If I don't hear anything within a week I'll just go ahead. Here's my revision as it stands: User:Jesdisciple/JavaScript --Jesdisciple (talk) 02:13, 14 May 2010 (UTC)

Thank You
I just want to say that as a person who knows some programming, but not JavaScript, and who now needs to know a little JavaScript, I am finding this book very helpful. Better than other things I've found so far. Communpedia Tribal (discuss • contribs) 23:04, 28 February 2017 (UTC)

Out-of-date
This book seems to be pretty out-of-date, with several obsolete topics still being featured (such as XMLHttpRequests). It would be a good idea to modernize the book somewhat, add pages about TypeScript and new functionality like the fetch api. Maybe a page can also be dedicated to the new operators, like the null-coalescing operator. And finally, we could include a page on popular frameworks like React/Vue. 2603:7000:E43F:9867:7D65:CD90:F560:AA4C (discuss) 03:07, 8 July 2022 (UTC)

+1. I will work on this in the next three months. With a focus on exercises for beginners. --Kelti (discuss • contribs) 14:34, 28 September 2022 (UTC)

After diving a little deeper into the subject, I have doubts whether it is possible to improve the book. I have read the old request for deletion (2013), but this is not my point. My main concerns are: So, my questions are: --Kelti (discuss • contribs) 06:58, 10 October 2022 (UTC)
 * There is a vast number of good Online tutorials and reference books for JS. What entitlement do we have for the additional publication of a JS wikibook? At least, we need one or more distinguishing features compared to the other publications: a different audience, a different level of detail, different usage rights, ....
 * The current book treats many issues closely related to JS: XMLHttpRequest, Ajax, DOM. To establish a higher degree of clarity we shall divide the pure JS issues (purpose of the language, syntax, concepts) from such aspects, which are not JS-specific (events, DOM manipulating, ...).
 * What is the purpose of the book? Tutorial, reference, examples and snippets, front-end focused, back-end focused?
 * What is our audience? Beginners or experienced programmers?
 * How to differentiate the book from similar publications?
 * How to split the pure language aspects from the other topics? Separate books with links to each other? Delete some pages?
 * How to organize books about the JS family: JS, ECMAScript, TypeScript, other derivates?
 * How to integrate popular frameworks?

No comments from anybody? --Kelti (discuss • contribs) 12:54, 13 October 2022 (UTC)
 * About the frameworks, as far as I can see in the other languages, it should be limited to one page max, and refer to a dedicated book if any. JackPotte (discuss • contribs) 14:57, 20 May 2023 (UTC)
 * About the audience, as the other book (Common JavaScript Manual) cannot really be the level one, what about beginners at the beginning of the book, and experts at the end? JackPotte (discuss • contribs) 15:00, 20 May 2023 (UTC)


 * To my mind, the purpose of the book is to provide a structure of topics that come under the larger topic of "JavaScript", provide compact description/treatment of each topic with plenty of examples, and provide the best links to online sources we can as a complement. For instance, I repeatedly return to JavaScript/Regular expressions to remind myself of the particular flavor used by JavaScript. --Dan Polansky (discuss • contribs) 12:16, 27 May 2023 (UTC)

Navigation
I register my opposition to the navigation bar that was recently added to the top right. It adds visual noise while adding almost no value. The table of contents is one click away, and for navigating to a next chapter, there are much less obtrusive aids. --Dan Polansky (discuss • contribs) 09:04, 20 May 2023 (UTC)
 * Hello, I think this might interest who's designed it. About the less obtrusive aids, do you please propose something like into:

There are three elements to decide: the header, the footer and the TOC. JackPotte (discuss • contribs) 14:48, 20 May 2023 (UTC)
 * Python Programming/Internet, or
 * PHP Programming/PHP Include Files or
 * A Quick Introduction to Unix/Directory Structure?
 * The means used by Python is fine: it is fine for navigation to take one line from the header and one line from the footer. It is my position that the TOC should not and need not be on the chapter page itself, to make the page as calm as possible; the TOC is available one click away from the header and the footer. The means used by PHP is basically fine but needlessly gaudy: no need to use strong green color. --Dan Polansky (discuss • contribs) 05:12, 21 May 2023 (UTC)
 * OK, I agree to use the Python book style here, but not its templates because on the contrary of nav or JavaScript, the previous and next pages are not dynamic. Moreover, JavaScript shows that there is no need for two inclusions when we can do one with both templates. JackPotte (discuss • contribs) 12:48, 21 May 2023 (UTC)
 * I do not insist on any particular template; my point is to avoid the sidebar as visually intrusive and low-added-value. I think some generic template could and perhaps should be used, not one specific to JavaScript. I think I was some very unobtrusive looking template that I liked a lot, one that used almost no color; I'll look if I can find it. --Dan Polansky (discuss • contribs) 07:19, 22 May 2023 (UTC)
 * The template used by GIMP/Text Tool looks excellent, very unobtrusive and elegant, except that the top does not link to the index, which it could, although the link to index is at the top above anyway. --Dan Polansky (discuss • contribs) 07:20, 22 May 2023 (UTC)

We shall distinguish between the two topics head/food navigation to next/previous page and fast navigation to important pages (the additional box at the top right).

A) next/previous: Writing a Wikibook is a little different from writing a physical book or an E-Book in that the Wikibook is divided into multiple, independent HTML pages. Obviously, such HTML pages must be arranged in a certain sequence. In the case of physical books or E-Books, the sequence is implicitly given.

Some of our templates use explicit linking by giving the name of the next and previous page. This is very cumbersome and I avoid all of them. (Is the author of page 46 willing to define "the next page is 47 and the previous one is 45"?) Other templates use the TOC mechanism and create the links dynamically. This is ok for me. The styling of the links (color, size, ...) is out of scope for me. Due to a physical issue, I don't see colors like other people. Therefore I avoid comments about this topic.

B) fast navigation: The fast navigation box was introduced to give the reader the chance to reach important pages and topics very quickly. It isn't a repetition of the TOC. Of course, it needs some space. This may be a problem, especially for smartphones. Possibly the community argues against such a fast navigation box. --Kelti (discuss • contribs) 15:15, 23 May 2023 (UTC)
 * We are talking a difference between 1 click and 2 clicks to reach the target page. There are too basic use cases: 1) read the book from the beginning to the end, for which the navigation box is unnecessary. 2) have a specific question and land on a particular chapter to have that question answered. None of the use cases require navigation box. Also of note is that navigation box is yet another page/place to maintain/update, in addition to the TOC and the chapters themselves. --Dan Polansky (discuss • contribs) 11:02, 27 May 2023 (UTC)
 * From looking at the revision histories, I find e.g. this: . I do not see why this had to be abandoned. The last thing Wikibooks need are arbitrary changes in the veneer or style with no substantive value; ideally, keep these things constant and focus on incremental changes and expansions of what the book already covers. --Dan Polansky (discuss • contribs) 12:18, 27 May 2023 (UTC)
 * [//en.wikibooks.org/w/index.php?title=JavaScript/Introduction&diff=next&oldid=4029234 It was obviously abandoned for the lack of dynamicity of the previous and next pages in the "prognav" template].
 * Now if I would sum up this debate, I would say that we all agree about the fact that these templates are better when dynamic and that the short embed TOC is too large for mobiles. So we need to vote:
 * For the previous and next page style (color and position).
 * For the presence of the TOC in the desktop view. JackPotte (discuss • contribs) 12:22, 28 May 2023 (UTC)
 * I have not said the navigation template is better when "dynamic". I guess that by "dynamic" you mean something like that the previous and next pages are not coded in the template invocation in the chapter itself but rather somewhere else. Where is the technique described and how is the mere mortal who wants to add a new chapter going to find the place to modify? That is what I gathered from Special:Diff/4193587. This diff introduced Template:Nav; why was the template abandoned later in favor of a book-specific template?
 * The book-specific template 'JavaScript' covers templates and categories that shall occur on every page: AutoHeader, Footer, BookCat, and Category:Sidebars. It summarises the common aspects of the subpages. --Kelti (discuss • contribs) 17:23, 29 May 2023 (UTC)
 * As for mobile, I did not say anything about mobile vs. desktop; I am on a desktop. I am in principle opposed to visually distracting elements with low added value that add maintenance overhead for anyone trying to work on the book.
 * In my view, everything was fine as for navigation templates before the change. The result looks unseemly (subjective taste) and is harder to maintain for mere mortals. As far as votes go, I vote for abandoning the navigation bar on both mobile and desktop, and leaving it to the users to click at the TOC at the top of the page, and using the TOC to navigate to chapters that are not directly linked from a chapter. --Dan Polansky (discuss • contribs) 07:40, 29 May 2023 (UTC)
 * As for colors and icons, I accept the current output produced by Template:Nav, with green background; I accept with the current output produced by Template:prognav, which has light yellow background; I prefer the output produced by Template:chapter navigation; what I oppose are the unseemly large arrows currently produced by Template:JavaScript. Thus, of the 4 options listed, I oppose only 1 of them, accept 2 of them, and prefer 1 of them. --Dan Polansky (discuss • contribs) 07:48, 29 May 2023 (UTC)

What constitutes a Wikibook?
A Wikibook consists of many pages. What criterion makes a page part of a particular Wikibook? Is it: Or is there no clear definition and every template (toc, nav, ...) can do what it wants? --Kelti (discuss • contribs) 15:17, 23 May 2023 (UTC)
 * The page is a subpage (recursively?) of the intended Wikibook?
 * There is a link to the page (recursively?) and the link points to the Wikibook domain?
 * Usage of a certain template?
 * I do not understand what these questions are aiming at. At any given point, all subpages of "JavaScript" are part of a single book, JavaScript. Whether they all belong to the book is another question. One could envision multiple books on JavaScript, if one wanted to, but that does not seem necessary or helpful at this point, does it? --Dan Polansky (discuss • contribs) 12:13, 27 May 2023 (UTC)
 * Sorry, I'm not a native English speaker. For me the two statements "all subpages of [/]JavaScript are part of ... JavaScript" and "whether they all belong to the book is another question" is not clear. Therefore I prefer an example: JavaScript/Glossary is a subpage of JavaScript, but it is not in the TOC of the book. Hence my question: Is it part of the DocBook JavaScript?
 * Of course, someone can create a second Docbook e.g.: JavaScript for Beginners and refer from its TOC to JavaScript/Glossary. Is JavaScript/Glossary part of the DocBook JavaScript for Beginners?
 * Your astonishment about my question leads me to guess that there is no clear definition.
 * The background of my question is: About what pages shall templates (navigation, PDF generation, printable version, ...) iterate over? Kelti (discuss • contribs) 15:56, 27 May 2023 (UTC)
 * I had created JavaScript/TOC OLD (which you renamed) for that, because it can order all the book subpages.
 * Concerning the pages belonging to several books, to avoid duplication, I propose to use inclusions. In the example above, that would imply to create a JavaScript for Beginners/Glossary containing:

JackPotte (discuss • contribs) 12:38, 28 May 2023 (UTC)


 * I don't plan to create a second Wikibook about JavaScript. It is only a theoretical example to clearify the question "What constitutes a Wikibook?". Also, the question doesn't have any relationship to a 'fast navigation box'. Kelti (discuss • contribs) 07:02, 29 May 2023 (UTC)
 * I am pretty confused from the above. One thing is clear: when you create a subpage like JavaScript/Glossary, you should add it to the TOC, as is the usual practice. As an aside, JavaScript/Glossary does not look like a glossary: it has a table with items that are too long for a glossary, which normally only provides a quick definition or a characterization; that should be clear from looking at various things called a "glossary". As for "DocBook", it does not seem to do anything with Wikibooks, does it? So how does "DocBook" relate to this discussion, if at all? --Dan Polansky (discuss • contribs) 07:58, 29 May 2023 (UTC)
 * Sorry for using the term "DocBook". That was a mistake. In all cases it should read "WikiBook". Kelti (discuss • contribs) 16:28, 29 May 2023 (UTC)

Chapter Primitive data types
I do not understand why it was necessary or useful to join(?) the separate chapters for Strings etc. to create single chapter JavaScript/Primitive data types. The last thing a Wikibook needs is an arbitrary restructuring; different people have different ideas about the ideal structure, and such changes in structure usually lead to to-and-fros with no genuine value.

Furthermore, from looking at the revision history of JavaScript/Primitive data types, I do not see any credit given to previous content; was the content a new writeup? Thus, was the original content of chapters Strings, etc. discarded and replaced with a new content? Why? What was wrong with the original text?

I would be happy to undo these changes, and maintain a stable long-term structure unless there are grave defects in that structure, which I do not see to be the case.

People should focus on incremental changes and expansions, not on arbitrary restructuring. --Dan Polansky (discuss • contribs) 11:54, 27 May 2023 (UTC)


 * From October 2022 until Januar 2023 I have done a reworking of nearly all pages, see the discussion Talk:JavaScript#Out-of-date. Concerning the original page variables and types, I splitted it into two pages because there is enough content for each page JavaScript/Variables and JavaScript/Data types. Unfortunatelly the second is no longer part of the TOC.
 * Furthermore, I believe that there should be one page for a description of all seven primitive data types (one page per primitive data type is also ok) plus additional pages for data types that are derived from Object (Array, Date, Error, Function, RegExp, ...). Hence a structure like this would be ok for me:
 * Variables (key words, initializaton, scope)
 * Data types
 * Primitive data types
 * Number
 * String
 * Objects
 * Array
 * Date
 * Maybe, some confusion arrised because I didn't do proper 'renaming' of old pages - instead I sometimes reused their name with divergent content. This may result in some cases in a mismatch beween page name and page content. Kelti (discuss • contribs) 15:16, 27 May 2023 (UTC)
 * Concerning the quality of the description of data type related 'functions', I tried to differentiate between properties, methods and constants of static Objects like, and methods of the data type. Perhaps we shall add a paragraph where this aspect is introduced. But in general, I consider that an improvement. Kelti (discuss • contribs) 15:27, 27 May 2023 (UTC)
 * Did you use any of the preexisting material in your merged content that you placed to JavaScript/Primitive data types? If so, which material did you use in the merged content? --Dan Polansky (discuss • contribs) 07:51, 29 May 2023 (UTC)
 * Concerning the quality of the description of data type related 'functions', I tried to differentiate between properties, methods and constants of static Objects like, and methods of the data type. Perhaps we shall add a paragraph where this aspect is introduced. But in general, I consider that an improvement. Kelti (discuss • contribs) 15:27, 27 May 2023 (UTC)
 * Did you use any of the preexisting material in your merged content that you placed to JavaScript/Primitive data types? If so, which material did you use in the merged content? --Dan Polansky (discuss • contribs) 07:51, 29 May 2023 (UTC)

Arbitrary restructurings are the bane of Wikibooks
I would like to make the general point that I believe arbitrary restructurings are the bane of Wikibooks. They undermine stability of books and chapters and all too often produce nothing of genuine value. It is much better to work in an incremental manner: expand existing chapters, and add new chapters. Restructurings are nearly invariably subjective, and should the will of original authors of a Wikibook prevail, they would lead to costly to and fros with no value. I would make a general appeal to editors to think twice before turning things upside down, apply colorful veneer, make unnecessary splits to chapters of a book that is under 200 KB, etc. --Dan Polansky (discuss • contribs) 08:02, 29 May 2023 (UTC)


 * +1. So, let us create a general, long term structure for this WikiBook. Kelti (discuss • contribs) 16:51, 29 May 2023 (UTC)

A) Here is my suggestion for a long term TOC:

Welcome
 * Hello World!
 * Introduction + Relation to other Languages (merged to a SINGLE page)
 * JavaScript within HTML
 * Helpful hints
 * Development tools (merged with 'Useful software tools')

Core Language Aspects
 * Variables (key words, scope)
 * Data types (explanation of the type system: 'primitive', 'Object', and wrappers for 'primitive' (boxing))
 * Primitive data type: String
 * Primitive data type: Number
 * Other primitive data types: Bigint, Boolean, Undefined, Null, Symbol
 * Objects (summary and distinction to primitive data types)
 * Arrays
 * Dates
 * Regular Expressions
 * JSON (delimitation to data type 'Object')
 * Operators
 * Program flow I: if, switch, try
 * Program flow II: loops
 * Functions
 * Object-oriented programming (OOP)
 * Objects (constructor, inheritance, access control)
 * Prototype-based syntax
 * Class syntax

Extended Language Aspects
 * Closures
 * Asynchronous behavior
 * Sequence generators
 * Automatic semicolon insertion (ASI)
 * Reserved words

Document Object Model and Dynamic Websites
 * Basics
 * Finding elements
 * Adding elements
 * Changing element's content
 * Changing element's styles
 * Removing elements
 * Restructure the DOM tree
 * Handling DOM events
 * Forms
 * Bookmarklets

Client/Server Programming (summary about AJAX, XMLHttpRequest, jQuery, Axios, Fetch API) Server Side Programming (summary about existing Webservers, frameworks, libraries) Miscellaneous
 * Debugging
 * Optimization
 * Shell

Appendices
 * Glossary (clear definition of similar terms. e.g.:function/method, argument/parameter, ...). This helps readers as well as authors.
 * Index
 * Links

Related Wikibooks
 * HyperText Markup Language (HTML)
 * Cascading Style Sheets (CSS)
 * Web development
 * WEB pages programming
 * Ajax programming
 * ActionScript programming
 * Coding Cookbook: JavaScript

Resources at Wikipedia and Wikiversity
 * JS at Wikipedia (Main page)
 * JS at Wikipedia (Category)
 * JS at Wikiversity - Introduction
 * JS at Wikiversity - Programming
 * JS at Wikiversity (Category)

External links
 * Website of ECMA-262
 * Latest specification (TC39)
 * JavaScript at MDN Web Docs in different languages
 * JavaScript tutorial at codecademy.com

B) My suggestions for general rules are: --Kelti (discuss • contribs) 11:07, 31 May 2023 (UTC)
 * All examples and descriptions are in ECMAScript 6 (2015) or higher
 * No mention of very old products or concepts (JScript, Internet Explorer, Netscape 7.x, ...)
 * As a counterproposal:
 * 1) Stop playing around with the structure; keep it as is, or perform minor, as if surgical, well justified incremental changes, and make use of edit summaries to document these incremental changes.
 * 2) Avoid nested chapters; keep the simple structure JavaScript/Chapter. It is sufficient for the subject.
 * 3) If you decide to merge chapters, always (i) create a chapter that results from an unmodified merger of the chapters being merged, and save it so it appears in the revision history of the new page, and (ii) indicate in the edit summary that you are doing a merge. Doing something else is rather disruptive and makes it harder to track the editing history of the Wikibook.
 * --Dan Polansky (discuss • contribs) 10:40, 2 June 2023 (UTC)

General rules
The following was proposed: I am not sure what problems these rules are trying to solve. If there are ocassional mentions of these things, not too numerous, I do not think it harms the utility of the material.
 * 1) All examples and descriptions are in ECMAScript 6 (2015) or higher
 * 2) No mention of very old products or concepts (JScript, Internet Explorer, Netscape 7.x, ...)

Instead of inventing rules and big projects turning things upside down, better work through incremental changes to produce objective value. --Dan Polansky (discuss • contribs) 10:43, 2 June 2023 (UTC)