Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

The Book of JavaScript

samzenpus posted more than 7 years ago | from the read-all-about-it dept.

Book Reviews 83

Michael J. Ross writes "Developers of Web sites, whether professional programmers or Web hobbyists, are oftentimes impressed by the more advanced functionality that can be achieved on a Web page using JavaScript. Yet these personal discoveries of JavaScript's power do not always motivate the developers to implement similar functionality on their own sites — partly because most of those custom-built JavaScript functions are cryptic, and make no attempt to show how the developer would customize the code for their own use. The majority of JavaScript books are of limited help in this regard, because they focus on the language details, illustrated only with code snippets. Many readers would benefit more from instruction via working examples, which is the approach used by The Book of JavaScript." Read the rest of Michael's review.

The book was written by David Thau, a.k.a. "thau!," a veteran of the Internet and computer programming — especially JavaScript, which he has taught to countless other programmers, through this book, as well as numerous courses, conference presentations, and the tutorials he has written for Webmonkey.

Published by No Starch Press, the second edition of The Book of JavaScript appeared in December 2006. The publisher maintains a Web page for the book, where visitors can find an online copy of the book's table of contents, excerpts from reader reviews, links for purchasing the paper and electronic versions of the book, a sample chapter ("Chapter 2: Using Variables and Built-In Functions to Update Your Web Pages Automatically") as a PDF file, the errata discovered by the author and readers (several reported so far), and a link to the author's companion site.

Unlike some books' companion sites, this one is worth a visit, and not just to see a working example of the tip box described in chapter 8, which is used to show how to create an array. Thau's site has links for viewing, running, and downloading all of the sample code in the book's figures. In addition, the visitor can obtain copies of the book's JavaScript libraries, for doing cookies, form validation, and plug-in detection. There are links for viewing and downloading the three sample Web sites. However, in his AntWeb site, at least as of this writing, none of the images are showing up on his homepage. Another problem, of much less importance, is the strange behavior of the "Websites" and "Freeware" options on his "Chapters" drop-down list box. Choosing either one takes the visitor to his "Websites" page, but always displays "Freeware" in the drop-down. It is hard to imagine that this behavior is intentional.

The book's material spans 528 pages, most of which is found in 18 chapters, covering a variety of topics: an overview of JavaScript's capabilities, alternatives, and limitations, among other less technical issues; variables and built-in functions; browser detection and simple control flow; rollovers, events, images, and the "document" object; window manipulation and properties; creating your own JavaScript functions; Web forms; arrays and iteration; timing events; frames and image maps; handling form input and strings; cookies; dynamic HTML, CSS, and DOM; AJAX basics; XML; server-side AJAX; a sample application (an online to-do list); and debugging JavaScript and AJAX. The book also offers four appendices: answers to chapter assignments; online resources (tutorials, sample code, AJAX sites, and AJAX frameworks); a complete reference to JavaScript's objects and functions; the code for the book's two longest applications, namely, the Italian translator and the to-do list.

This second edition serves as a follow-up to the well-regarded first edition that came out seven years earlier. Both the book and the language itself have clearly withstood the test of time. There are several reasons for the popularity of that first edition: It taught the language and its capabilities largely through the use of complete JavaScript functions, each of which served as an illustrative example of not just the elements and rules of the language, but also straightforward ways of accomplishing common tasks in JavaScript. After all, looking at sample code is how most programmers prefer to learn or verify how a language works.

The book assumed no prior knowledge of JavaScript or any other computer language, on the part of the reader. This characteristic not only set it apart from the large number of other JavaScript titles published at that time, but it made the book more attractive to people new to programming in general and Web programming in particular. Such readers might also favor this book over others because of the author's approachable writing style, in which he fully explains topics in a leisurely manner, without the terseness seen in most programming language books. This is not to say that brevity in technical works is ever a mistake per se; the busy professional programmer wants to find answers as quickly as possible. But such brevity can quickly prove frustrating to non-techies, who lack the background for understanding terse explanations and for knowing where they can turn for clarification.

All of these laudable attributes of the first edition have been carried over into this latest edition. The primary change found in this second edition, is the coverage of AJAX (asynchronous JavaScript combined with XML). Even though the additional material substantially increases the length of the book, by 124 pages, the end result is still far from unwieldy — mostly due to several factors: The book's table of contents, along with the index, are detailed enough to make it relatively easy to find a particular topic in the book, assuming that it is included. The subsection listings in the table of contents, like good source code, make liberal use of whitespace for readability. In the text itself, coloring the headings and note numbers blue make them stand out.

Aside from the aforesaid problems with the book's companion site, there are a few other areas for improvement: It was noted earlier that the last appendix contains the sample code from chapters 15 and 17. The author states that these code listings were located in an appendix, rather than the chapters themselves, because they are too long. Actually, they comprise only a dozen pages, which would have been better located in the chapters where the reader expects to see them, and where they would be close at hand for referencing. The first listing is only two pages long, and definitely should be located in chapter 15. Even for the second listing, if the author is concerned about readers getting frustrated flipping through the 10 pages to find the continuation of the chapter's discussion, a simple note at the beginning of that code, as to what page the discussion is resumed, would be sufficient.

Some fundamental language elements of JavaScript are introduced fairly late in the book. For instance, it is noted above that an explanation as to how to create an array — an essential concept in just about any procedural language — is not found until the eighth chapter, on page 134. This is more than one third of the way into the book's 18 chapters. On the other hand, given that the author has chosen to present these language concepts, for the most part, only when needed and when describing the sample code, this later introduction of some key concepts might not prove much of a problem to most readers. However, this is a case in which the completeness and accuracy of the book's index, are even more critical than usual. In this regard, the book does not fail the reader, as the index appears to provide enough coverage.

The formatting of the code throughout the text is not entirely consistent, as evidenced by some open braces appearing on their own lines, thus wasting space, and in other cases on the same line as the preceding parenthesized expression, though separated by a pointlessly large number of spaces. Code level blocks are indented two or four spaces, seemingly at random. Continuation lines are indented exactly the same; they would be more clear if they had double the number of spaces as code level blocks. Of more importance to the reader attempting to figure out what code is serving what purpose, there are far too many large chunks of code lacking any comments, which are needed, since much of the code is not self-describing. In most of the functions, the only comment lines are those for hiding the JavaScript from outdated browsers — a practice that should have been phased out in this latest edition.

Any experienced programmer who needs a complete JavaScript reference book, or a book that covers all the language's elements in fine detail, would be best served by choosing a different book from this one. On the other hand, once they had secured such a book, they would likely find David Thau's contribution an enjoyable source of ideas on what can be done using JavaScript capabilities. For anyone who wishes to learn JavaScript in a practical and relaxed way, by reading clearly explained sample projects and their code, should be well pleased with The Book of JavaScript.

Michael J. Ross is a Web programmer, freelance writer, and the editor of PristinePlanet.com's free newsletter. He can be reached at www.ross.ws, hosted by SiteGround.


You can purchase The Book of JavaScript from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

Sorry! There are no comments related to the filter you selected.

Subtitle of the book (1)

operagost (62405) | more than 7 years ago | (#18266824)

Javascript: It's Not Just for Annoying Spammy Popup Ads Anymore!

Re:Subtitle of the book (4, Informative)

FooAtWFU (699187) | more than 7 years ago | (#18266988)

Poor JavaScript is the world's most misunderstood programming language [crockford.com] . But it's really kind of neat. The browser environment isn't too hot, but aside from that and a few stupid quirks (string concatenation / addition issues, especially) it's a neat little programming language where functions are actually first-class objects; you can do some pretty nifty inheritance things with this, building objects' behavior by aggregation...

Of course, you'll need a decent library like MooTools or Prototype or such if you want to keep your programming sane, and especially if you want to do good stuff in a web browser (they abstract away an enormous swath of the IE vs Mozilla-type vs Opera/etc compatibility issues).

Re:Subtitle of the book (1)

gfxguy (98788) | more than 7 years ago | (#18267934)

That was always my problem for any kind of heavy use of Javascript. I use it for a few convenience things, but I balk when I have to have the same code multiple times for various browsers, or have my code littered with if's to determine if it's IE to either not do something or do something extra.

Re:Subtitle of the book (2, Informative)

hobo sapiens (893427) | more than 7 years ago | (#18268454)

Yeah, that's the way it used to be. Prototype is what I use, because along with a very useful AJAX library it has several useful tools that totally abstract browser differences. For example, it has the $() function. Plug the id of an element in there like such: $('chewbacca'). Assign that to a var, and you have an object var that references the fully qualified element regardless of which browser you are in.

That's pretty simple actually. I used to have my own library that did that and more. But Prototype also does some totally awesome AJAX stuff, and adds useful functions that simulate methods that SHOULD exist (like document.getElementByClassName(), which does what its name implies.) You can get prototype here: http://www.prototypejs.org/download [prototypejs.org] . There is even an (unofficial) reference here: http://www.sergiopereira.com/articles/prototype.js .html [sergiopereira.com] .

I use this all the time, and it is a fantastic library. I never have to worry about feature sniffing or *shudder* browser string sniffing.

If you are on an intranet and you don't have to worry about some schlub having netscape 1 or something, then you can really do some very cool stuff with javascript (like AJAX) that makes the user experience much much better. Just be subtle with it. Going over the top with javascript and AJAX just makes you look ridiculous. If you are on the internet, I am not sure how well prototype works with ancient browsers (IE 3, etc). But unless you are amazon.com, who the heck cares?

Re:Subtitle of the book (1)

hobo sapiens (893427) | more than 7 years ago | (#18268520)

a few stupid quirks (string concatenation / addition issues, especially)
Yeah, my favorite one right now is how datevar.getYear() returns 107 in Firefox and 07 in IE. Just use datevar.getFullYear(), I know. But still...if you didn't know that imagine how frustrating it could be to have some date code return different stuff in different browsers?

Just like you said, aside from stuff like that, javascript is very powerful. Everyone has a somewhat new browser, so everyone can use it.

Re:Subtitle of the book (1)

lazybeam (162300) | more than 7 years ago | (#18274012)

What was the function that returns 2007 in 2007 but returned 99 in 1999? I always think of that misfeature when I hear the Gorillaz song 19-2000. :) (That was a common Y2K bug, people concatting "19" to a two-digit-year function)

Re:Subtitle of the book (1)

anomalous cohort (704239) | more than 7 years ago | (#18268982)

The fact that functions are objects is cool but I have many complaints about JavaScript. The implementation of object orientation as a hash table with a dot notation is a far cry from object orientation.

I have never used a java script environment outside of a web browser so I pretty much associate the two as the same. The fact that the this keyword has very different semantics depending on how the member function was called is a major stumbling block for me. Yes, prototype binding saves the day but it reflects poorly on the programming language to have to depend on a particular library to fix something as basic as the this keyword.

Also, you can do all kinds of things with an HTML DOM node in java script that is bad and should be illegal but you never get an error or exception. The script just quietly stops running. That kind of behavior is not my idea of a good programming language.

Re:Subtitle of the book (1)

FooAtWFU (699187) | more than 7 years ago | (#18271426)

The fact that functions are objects is cool but I have many complaints about JavaScript. The implementation of object orientation as a hash table with a dot notation is a far cry from object orientation.
What difference does that make to you as a programmer, practically? Any dynamically interpreted language already uses a hash of some sort for runtime resolution of values in symbol table. Is this somehow less valid because it isn't precomputed? I guess you lose some of your type-safety-ness and are allowed to assign meaningless values to stupidly named properties - it doesn't enforce as strict a discipline or anything - but hey, it's a scripting language, and this isn't a limitation on its object-orientation. So what object-orienting features exactly are you looking for that JavaScript doesn't provide? You can still assign methods to an object's prototype for classical inheritance, as well as assigning methods directly for some sort of aggregation or multiple inheritance. Something like Prototype/MooTools will even provide you with some syntactic sugar to define classes in a more traditional looking way. The one thing I could see you complaining about is data hiding and private variables - okay, those are a little trickier (and involve setting an object's functions that use these private variables in the constructor at runtime; this page [crockford.com] describes the practice...)

You could come up with a fine case for type safety issues, but I'm just not seeing your Far Cry from Object Orientation here.

Re:Subtitle of the book (1)

anomalous cohort (704239) | more than 7 years ago | (#18272286)

So what object-orienting features exactly are you looking for that JavaScript doesn't provide?

Proper overriding of members such that the base class implementation is still available (e.g. super.mymethod()).

The one thing I could see you complaining about is data hiding and private variables - okay, those are a little trickier and involve setting an object's functions that use these private variables in the constructor at runtime.

Any well defined task can be programmed in any general purpose programing language. So whether or not something is possible is not a good measure of a programming language. By that criteria, all general purpose programming languages are identical. Rather, how easy it is to do something is a better measure of a programming language. Yes, it is possible to fake all kinds of object oriented features in java script. Both features mentioned here can be faked but not easily.

Any dynamically interpreted language already uses a hash of some sort for runtime resolution of values in symbol table. Is this somehow less valid because it isn't precomputed?

I don't believe that my criticisms of java script here are in some kind of static versus dynamic vein. I'm a big fan of python and ruby but I also appreciate Java, C++, and even C# (no flames, please). There are certainly differences between static and dynamic OOP and it does take some getting used to; however, that is not what I am complaining about in java script.

Re:Subtitle of the book (1)

CTho9305 (264265) | more than 7 years ago | (#18269426)

I like JS. Taken together with canvas, you can do some pretty interesting things: some toys [ctho.ath.cx] (including a 3d graphics engine) and some games [ctho.ath.cx] (see if you can beat the Robots high score). I think this game [ctho.ath.cx] is probably the most interesting (unfortunately I never got around to implementing the transportation logic, but it's still an amusing demonstration of what's possible).

I got into this originally because I spend a lot of time working on SeaMonkey (and sometimes Firefox / Thunderbird), which has huge amounts of JS. It's always fun to do things in languages which are clearly the wrong choice - like the JS raytracer.

Re:Subtitle of the book (1)

Watson Ladd (955755) | more than 7 years ago | (#18270094)

The browser environment isn't too hot, but aside from that and a few stupid quirks (string concatenation / addition issues, especially) it's a neat little programming language where functions are actually first-class objects; you can do some pretty nifty inheritance things with this, building objects' behavior by aggregation...
Oh, just like you can with Lisp, Scheme, Smalltalk, Standard ML, and Perl?

Re:Subtitle of the book (1, Funny)

balbord (447248) | more than 7 years ago | (#18267092)

<script language=javascript>
while(1==1){
alert('pwned');
}
</script>

Mwhahahahah
Phear my mad skillz!

Hunrf?!?!

Re:Subtitle of the book (1)

AKAImBatman (238306) | more than 7 years ago | (#18267158)

Browser: "This script appears to be running slowly. Would you like to kill it?"

Me: "Yes<click>, please"

Browser: "Would you like me to smack balbord while I'm at it?"

Me: "Yes<click>, please"

(Okay, so that last part doesn't really happen. But there's always hope in the next version of Firefox!)

Re:Subtitle of the book (0)

Anonymous Coward | more than 7 years ago | (#18268934)

Speaking of annoying... "oftentimes". WTF! Nevertimes do I find myself impressed by the use of this pseudo word. Speak English. Please.

sorry guys! (1)

alfs boner (963844) | more than 7 years ago | (#18266862)

I would never socialize with a slashdot user.

cmon (1)

revlayle (964221) | more than 7 years ago | (#18266918)

AJAX is not "asynchronous JavaScript combined with XML" - 'cause, then, that would be AJCWX, and that is totally unpronounceable. ;)

Re:cmon (1)

Anpheus (908711) | more than 7 years ago | (#18268576)

Some of us don't speak your puny earth languages, you insensitive clod!

Re:cmon (1)

revlayle (964221) | more than 7 years ago | (#18270230)

says YOU, i almost broke my mouth trying to say AJCWX

Re:cmon (1)

teh*fink (618609) | more than 7 years ago | (#18271982)

...that would be AJCWX, and that is totally unpronounceable.

haha, not to us poles!
silly americans...

Time to Learn How to Program (4, Informative)

AKAImBatman (238306) | more than 7 years ago | (#18266936)

Developers of Web sites are oftentimes impressed by the more advanced functionality that can be achieved on a Web page using JavaScript. Yet these personal discoveries of JavaScript's power do not always motivate the developers to implement similar functionality on their own sites

If I may make a supposition, this occurs most often because programmers think they know how to program in Javascript, but don't have the first clue. That's why we see lots of code like:

<body onKeyDown="doSomeStuff()">
Or:

domelement.innerHTML = "<p>"+equation+"</p>";
Anyone want to guess what happens when "equation" is equal to "x

function doSomeStuff(event) {...}
 
document.addEventListener("keydown", doSomeStuff, false);
^^-Much more portable as it can be constrained to a single JS file without overriding the ability of other code to receive events.

var paragraph = document.createElement("p"); //this should really be a DIV
 
paragraph.appendChild(document.createTextEl ement(equation));
domelement.appendChild(paragrap h);
^^-Seems more complex, but does not suffer from special character issues -AND- can be far less code when used in well-written algorithms.

Then there are people who do this:

for(i=0; i<10; i++) doSomething(i);
I hope you don't have a loop in doSomething, because you may accidently modify the global variable "i". The correct solution is to make it a local variable like this:

for(var i=0; i<10; i++) doSomething(i);
Lastly, people complain that Javascript isn't Object Oriented. To which I can only act annoyed. What is this?

function LightBulb(on)
{
    this.on = on;
 
    this.isOn = function() { return this.on; }
    this.setOn = function(on) { this.on = on; }
}
 
var mybulb1 = new LightBulb(true);
var mybulb2 = new LightBulb(false);
 
alert(mybulb1.isOn()+" - "+mybulb2.isOn());
If that still doesn't convince you to take another look at Javascript, well maybe this will:

http://www.youtube.com/profile?user=thewiirocks [youtube.com]

It's a set of videos showing Javascript games in development for the Nintendo Wii. Nothing special here, just Javascript + Canvas. The Tetris game even has a demo here:

http://java.dnsalias.com/tetris/ [dnsalias.com]

Make sure you have a browser that doesn't suck.

I hope you all consider taking another look at Javascript. Maybe this book is for you, maybe it isn't. But there is a LOT of potential to release.

Re:Time to Learn How to Program (1)

AKAImBatman (238306) | more than 7 years ago | (#18266996)

Ha! I got bit by my own bug! This:

domelement.innerHTML = "<p>"+equation+"</p>";
Anyone want to guess what happens when "equation" is equal to "x


is supposed to say this:

domelement.innerHTML = "<p>"+equation+"</p>";
Anyone want to guess what happens when "equation" is equal to "x < y"? (Hint: Nothing good.)


Just more proof of why coding for the DOM is a good idea. Microsoft's extension crud may seem convenient at the moment, but it's just hurting you in the long run.

Re:Time to Learn How to Program (1)

multipartmixed (163409) | more than 7 years ago | (#18269796)

If you wrote "equation = x y", then of course nothing good will happen, equation is effective a bool and will get toString()'d during concatenation.

However, most of your examples don't have squat to do with the core language, and everything to do with the DOM. Or what *you* think is a useful way to express an idea.

Just because it's possible to manipulate the DOM to insert an event listener doesn't mean that it's practical. Especially in the case when your attaching say events to HTML elements that run javascript library code. In that case, you're developing an HTML document, use the HTML attribute to key the event. Writing a one-line script to modify the DOM thereafter is not only confusing, it is retarded.

And, for the record, I'm a big fan of JavaScript, and use it quite extensively outside the browser; often when I need to deal with either large lists of things or things with lots of properties. My preferred interpreter is NJS, and I have used it to implement arbitrary object persistence, completely in JavasScript, along with several other medium-sized utility libraries, one of which contains a powerful XML DOM subset and event-triggering XML subset parser without DTD validation or entities.

Your problem is that you're a "my way or the highway" "I'm better than you are zealot". Get your head out of your ass.

Re:Javscript Object Oriented? (1)

Lord Bitman (95493) | more than 7 years ago | (#18267104)

I have no reason to be annoyed with "Javascript is not object-oriented", because it really is such an obscure bit of information. You're actually the first place I've ever seen to even mention it. Sure, I've noticed it used in some places, to which I thought "Javascript is object oriented? I didn't know that.", but nobody seems keen to tell anyone else ;)

Re:Javscript Object Oriented? (1)

AKAImBatman (238306) | more than 7 years ago | (#18267204)

"Javascript is object oriented? I didn't know that.", but nobody seems keen to tell anyone else

The frightening part is that it's not that obscure. The Client-Side Guide [sun.com] that Netscape used to publish (up until the ECMA standard was established), has several detailed sections on written OOP code in Javascript. Including multiple methods for handling inheritence! The problem is that no one read Netscape's documentation. Everyone "learned" Javascript by modifying some poorly-written script they found on the Internet, just so they could make text scroll across the status bar of the web browser.

And then developers wonder why they never knew XYZ about Javascript. :-/

Re:Javscript Object Oriented? (0)

Anonymous Coward | more than 7 years ago | (#18267392)

Multiple methods? You can build up objects in C or Perl, but they are certainly not object-oriented languages. A basic feature of an object-oriented language is that it provides standard semantics for all objects written in that language.

An object-oriented design can be implemented on any platform.

Re:Javscript Object Oriented? (1)

AKAImBatman (238306) | more than 7 years ago | (#18267568)

An object-oriented design can be implemented on any platform.

Indeed it can. However, Javascript was built with OOP in mind. Its multiple paths through everything is a nod to the fact that it's still a scripting language. i.e. Designed for a blend of brevity, flexibility, and fast interpretation. That's why Javascript has about three different methods to do everything.

Because sometimes:

var myobj = {a:10, b:"Hello World!", c:function(){var x = ""; for(var i=0; i<this.a; i++) x += b+"\n"; return x;};
is preferrable over:

function MyObject()
{
    this.a = 10;
    this.b = "Hello World!";
    this.c = function()
    {
        var x = "";
 
        for(var i=0; i<this.a; i++) x += b+"\n";
 
        return x;
    };
}
 
var myobj = new MyObject();
It all depends on what you're trying to accomplish. Javascript gives you the most flexibility in exchange for somewhat "soft" semantics. Such is life.

Re:Javscript Object Oriented? (1)

MemeRot (80975) | more than 7 years ago | (#18268880)

My favorite use for the squiggly brace object declaration is to use it to pass a variable number of parameters to a function. Just define the function to take one object, and load that object up with whatever data is relevant. Easy way to future proof functions when you know you'll probably be adding more parameters in the future.

Re:Javscript Object Oriented? (0)

Anonymous Coward | more than 7 years ago | (#18269922)

You can pass any Javascript function any number of arguments. If you pass less than the defined parameters, the surplus variables are "undefined". If you pass more than the defined parameters, you can get the values from the parameters[] array, which stores all parameters.

Re:Javscript Object Oriented? (1)

hobo sapiens (893427) | more than 7 years ago | (#18270212)

Ah, yes JSON. I like that. Also cool is creating array objects using []; This is the foundation of many AJAX programs I have written. You write a service that passes something like:

[
['chris','jones','7182232000','programmer'],
['miles','davis','7182232000','musician'],
['hobart','macarthur','7182232000','lawyer'],
['bobo','clown','7182232000','clown'],
['chew','bacca','7182232000','wookie']
]

Leaner than XML, and you have a wonderful 2D array. Just return it to the page via an http request, and you have easy, lean, and fast AJAX code. Evaluate the object, loop over it, build HTML elements, et viola! instamatic content. Good stuff. And they say Javascript isn't powerful. Arrays, functions, they are all objects. Just have to tap into the power of the language.

Re:Javscript Object Oriented? (1)

FireIron (838223) | more than 7 years ago | (#18268148)

Gosh darnit AKAImBatman, stop spreading the secret of OO-JS everywhere!!! How are we supposed to look like genius web programming wizards if everyone knows how our tricks work?

;-) j/k ;-)

Re:Javscript Object Oriented? (1)

Gospodin (547743) | more than 7 years ago | (#18268324)

Heh, yep. I've been interviewing potential web application developers for months, and one of the things I try to probe is how much they really know about Javascript. So far I've met exactly zero who knew more than <a href="javascript:void(0)" onclick="alert('kewl')">.

Re:Javscript Object Oriented? (0)

Anonymous Coward | more than 7 years ago | (#18267754)

Object oriented Javascript is used everywhere, if you care to look. It's the easiest abstraction which allows a script to be used in more than one place on the same page if it has to keep some state. It also avoids name clashes between global variables, which is important because Javascript programmers tend to use short names to save bandwidth. Clearly defined interfaces allow for compression of all internal variable names without harming external compatibility. If you're using Javascript for more than event handlers which hide and show pieces of the DOM, you should consider using OOP for your own scripts.

Re:Javscript Object Oriented? (1)

Lord Bitman (95493) | more than 7 years ago | (#18268070)

Used lots of places (especially recently). I specifically said that in my first post: I did care to look, and low-and-behold it had objects.
But look for a javascript tutorial. You'd not guess that it allows user-defined objects from the first five hits, and you won't bother to look further since the first five hits seem so in-depth.

I've never read the official C standard, but because I use it every day, I assume I know C.
I hear the official javascript standard is poorly-written crap. I've never read that either.

Standards are for idealists. Other people's code is for programmers. When I used javascript, I read other people's code until I had the basics down, then bought a book and read that. I haven't used it in years (for anything non-trivial), but recently needed to do something, so I read other people's code. Hey look, objects! The book didn't mention those..

but then I use perl, so what's a "standard"?

Re:Javscript Object Oriented? (1)

multi io (640409) | more than 7 years ago | (#18269078)

I learnt JavaScript from the standard. Took about two weeks. Yes, the standard is difficult to read, but at least it's complete, which cannot be said about virtually all the books and tutorials about JavaScript -- indeed, if you've read those, you may think you know everything when in fact half the features of the language have completely eluded you because they weren't even mentioned.

Unfortunately, I found out about Douglas Crockford's lectures [yahoo.com] only *after* reading the spec :-\

Re:Time to Learn How to Program (0)

iluvcapra (782887) | more than 7 years ago | (#18267578)

Lastly, people complain that Javascript isn't Object Oriented. To which I can only act annoyed. What is this?

That's a first-class function or closure, not a class. You still can't do class or private and protected methods using this hack, nor can you do any meaningful inheritance or mixins.

You're right, Javascript is a good language with an unfortunate reputation, but it ain't object oriented. Its functional, and thus frameworks are built with first-class function and closures.

Re:Time to Learn How to Program (1)

AKAImBatman (238306) | more than 7 years ago | (#18267746)

You're right, Javascript is a good language with an unfortunate reputation, but it ain't object oriented.

You don't need a class/method design to be object oriented. Only the OO purists are dead-set on that. OOP is a style of programming, with some languages providing first-class support while other's do not. Nearly every language can be coded in an OO-manner to some degree. Javascript, thankfully, got fairly decent support from the get-go despite its intended use as procedural scripting. That makes a big difference when doing DHTML/AJAX scripts today.

However, if you happen to be an OO purist, you'll be happy to know that ECMAScript 4.0 (and related Javascript 2.0) provides first-class support for objects. Proper object definitions, optional typing, static properties, access control, the whole shebang. Technically, the spec is still being reviewed. But at least one engine decided to jump the gun. ActionScript 2.0 (aka Adobe Flash) already supports these features. The code for that engine is being used to construct Tamarin, the next generation of Mozilla Javascript engine. =)

Re:Time to Learn How to Program (2, Interesting)

null etc. (524767) | more than 7 years ago | (#18267778)

Re:Time to Learn How to Program (1)

iluvcapra (782887) | more than 7 years ago | (#18268104)

Thanks for the link, that's interesting.

Re:Time to Learn How to Program (1)

suv4x4 (956391) | more than 7 years ago | (#18268556)

This link is a good way to win in a discussion with ill-informed opponents.

Scope hacks are not a way to achieve member visibility, it's just that: a hack.

It adds overhead to the constructor, wastes memory by keeping the construction activation object alive long after the constructor function has returned, doesn't let the public methods access the "private" ones (ooops...), doesn't resolve the issue of protected members.

Well, for protected members maybe it doesn't matter since extending "classes" in JS is hell anyway (no standard way to call a super method, no standard way to create a child class without running the constructor on its prototype /terribly wrong, and could lead to malfunctioning code unless manually taken care of/).

Re:Time to Learn How to Program (0)

Anonymous Coward | more than 7 years ago | (#18267864)

Javascript is a prototype based OO language. Inheritance is achieved by assigning an object (of the parent "class") as the prototype of the new "class". The lack of private/protected methods is annoying, but it's certainly fitting for a loosely typed language like Javascript.

Re:Time to Learn How to Program (1)

Maian (887886) | more than 7 years ago | (#18273804)

Private members

Do you consider Python to be object-oriented? The "private" members of classes on Python are defined such that the names are prefixed with 2 underscores, i.e. __foo is private while bar isn't. The private var names are mangled so that they aren't easily accessible outside the class, but they are still technically public.

You can use this same idiom with JavaScript - just prefix the members you intend to be private with 2 underscores (or something equivalent). There's no name mangling in JS, but that's not really important. The biggest downside to this approach is that object enumeration (for (k in o)) still enumerates over private vars.

You could also take advantage of closures to simulate private members, as has already been demonstrated elsewhere here, but I generally don't recommend that since it does use more memory and is slower.

Inheritance

JavaScript is a prototype-based language, where each prototype itself can have a prototype, and so forth. When you do obj.prop, the engine traverses this prototype chain to search for a property called "prop". I call this prototype inheritance.

To do mixin inheritances, just copy all the properties of the mixin object with the target object's prototype (using object enumeration):

for (var k in mixin)
klass.prototype[k] = mixin[k];

If you're coding for Mozilla JavaScript (for intranet or non-client-side stuff), you can take advantage of its nonstandard __proto__ property to handle mixins:

function Serializable() {}
Serializable.prototype.serialize = function() { print("serialize"); };

function Base() {}
Base.prototype.foo = function() { print("foo"); };

function Klass() {}
Klass.prototype = new Serializable();
Klass.prototype.__proto__.__proto __ = Base.prototype;

x = new Klass();
x.serialize();
x.foo();

Re:Time to Learn How to Program (1)

herve_masson (104332) | more than 7 years ago | (#18267580)

If I may make a supposition, this occurs most often because programmers think they know how to program in Javascript, but don't have the first clue. That's why we see lots of code like:

Well, sure, I'm with you on this one, but you have to admit that this is how most of those programmers are "teached" from javascript documentation sources (not even mentionning those "100 great javascripts" web sites). The diversity and absurdity of documentation surrounding JS and web development reached a dangerous level. If this book cleanup some of that mess, that'll be a very good news.


for(i=0; i<10; i++) doSomething(i);
I hope you don't have a loop in doSomething, because you may accidently modify the global variable "i". The correct solution is to make it a local variable like this:


talking about that, having a global scope by default for variables is one of my top grief on javascript; it's just too easy to make a mistake. And the fact that variable scope is not bound to the containing bloc is really annoying too, even though less often problematic.

Aside from a few quircks like that, and despite the inherent difficulty to make anything working on all browsers (unrelated to JS), I really appreciate the flexibility and the power of this language.

Re:Time to Learn How to Program (1)

MemeRot (80975) | more than 7 years ago | (#18268928)

If you're looking at performance a lot, declaring your loop variable outside of the loop helps. Which makes sense, why declare it every time you loop, but doesn't match any of the normal code you see out there.

Re:Time to Learn How to Program (0)

Anonymous Coward | more than 7 years ago | (#18268122)

I hope you don't have a loop in doSomething, because you may accidently modify the global variable "i".

Either you have a global variable called "i", in which case you'll clobber it whether or not doSomething has a loop in it; or you don't have a global variable called "i", in which case it doesn't matter if doSomething has a loop in it. It looks like you've assumed that if there isn't a global variable called "i", then it will get created, but that isn't the case at all.

Really, if you're going to lecture others about JavaScript scoping, at least have some idea about how it works yourself.

Re:Time to Learn How to Program (1)

AKAImBatman (238306) | more than 7 years ago | (#18268350)

What the heck are you talking about?

It looks like you've assumed that if there isn't a global variable called "i", then it will get created, but that isn't the case at all.

That is exactly the case. Here's a bit of test code for you to try:

<html>
<script>
    function test()
    {
//This will only run once!
        for(i=0; i<10; i++) doSomething(i);
    }
 
    function doSomething(iteration)
    {
        alert(iteration);
 
        for(i=0; i<10; i++)
        {
//does nothing. This is an example
        }
    }
 
    test();
</script>
</html>
And how many times does the alert pop up? (Hint: It's not 10.)

Really, my dear AC. If you're going to lecture others about JavaScript scoping, at least have some idea about how it works yourself. :-P

Re:Time to Learn How to Program (1)

suv4x4 (956391) | more than 7 years ago | (#18268218)

Congratulations, you're a zealot. Who exactly invited you to paste your default JavaScript rant here, simlpy because the article is about a JavaScript book? Did you just wanna "let it out" since noone around you has idea what JavaScript means?

Both the DOM API and innerHTML have their place, and event handlers attached in the tag as attributes, and even eval() (yes OMGWTFBBQ!! I suck!!) can be useful for plenty of purposes, next to the "better" approaches you advertise.

You're simply repeating well known cliches here, and for what purpose exactly? A really good developer knows how to use the tools at his disposal and doesn't discriminate against a technique if it's the best way to achieve a result. A pseudo good developer simply repeats what his buddies told him is "better" and what is "lame".

Oh.. and by the way "addEventListener ... [is] much more portable as it can be constrained to a single JS file without overriding the ability of other code to receive events".

While you have a point for the multiple events, what does "portable" mean to you? IE doesn't support it (attachEvent is the alternative, but it's different in many very subtle ways), but who cares about measly ~90% of the web users. Not good developers for sure!

And for the record: prototype hacks are NOT modern OOP, if you believe OOP just those hacks, I advise you to take a look at the ECMA4 proposal (implemented in Flash 9 as "ActionScript 3", which is also reference implementation for JavaScript 2).

Of course, maybe ECMA is just stupid and we should be stuck with the awesome prototypes.

Re:Time to Learn How to Program (1)

AKAImBatman (238306) | more than 7 years ago | (#18268894)

Who exactly invited you to paste your default JavaScript rant here, simlpy because the article is about a JavaScript book?

1. It's not a default "cut and paste" rant. It's one I made just for this article. ;-)

2. That "Reply" button looked awefully inviting...

If truly you're wondering why I suddenly broke into a rant, it's because I've seen these articles too many times. Everyone assumes they already know Javascript, ergo, this book is not targeted at them. Well, someone needed to burst their bubble. Just look at the responses past my own! "Javascript is so easy it doesn't need a book" and "all you need is [insert crutch] library?" I'd say these people have a LOT to learn!

Both the DOM API and innerHTML have their place

I will agree that innerHTML has an occasional place. But not as an override to the DOM. Rather, it's much more useful in enhancing the scripabilty of the DOM. For example, when you highlight a section of text in Mozilla and request "View Selection Source". Being able to see the innerHTML snippet is very useful. It is also useful in serializing and deserializing HTML snippets.

Outside such specialized situations, it is NOT useful in dynamically modifying the HTML. In fact, it becomes a very dangerous tool capable of causing its user much harm. (Which it regularly does.) Yet it's still the most popular method of modifiying the DOM!

even eval() (yes OMGWTFBBQ!! I suck!!) can be useful for plenty of purposes

"eval()" has all kinds of wonderful uses! For example, it's great if you serialize a data object using "toSource", then deserialize it using "var x = eval(source);" Obviously it provides a great deal of power that can be (and is) abused. Thankfully, it's not abused too often.

It's much more important to open people's eyes to the mistakes they make daily. For example, a failure to use the DOM 2 Event model can cause all kinds of problems. Not the least of which is competing event handlers that overwrite one another.

You're simply repeating well known cliches here, and for what purpose exactly?

Hey, now. They're far from cliche, yet. There's still a huge problem out there of coders misusing and abusing Javascript because they think they know how to program in it. I'm hoping that seeing what they're doing wrong will open a few eyes.

A pseudo good developer simply repeats what his buddies told him is "better" and what is "lame".

Nice shot. But you missed. ;)

While you have a point for the multiple events, what does "portable" mean to you?

I was referring to code portability. Using the DOM 2 Event system allows your code to be properly encapsualted in its own little world. That allows for the construction of libraries that don't much care about other libraries you might be using. The DOM 0 event system is an all-or-nothing approach that causes no end to pain and suffering.

FWIW, it's possible to make the DOM 2 system fully portable across browsers. (Which is to say, FIX that #@!$@!!! excuse for an upgrade that Microsoft calls Internet Explorer 7.) The trick is to dynamically patch IE's DOM before any other libraries are called. There's a fairly good library for that here [lojjic.net] . There are actually quite a few more out there, but I'm not going to dig them up just now.

I advise you to take a look at the ECMA4 proposal (implemented in Flash 9 as "ActionScript 3", which is also reference implementation for JavaScript 2).

Funny, I was just mentioning that to another poster elsewhere in this thread. Perhaps my post was what gave you this idea? ;-)

BTW, Flash implements most of ECMAScript 4.0 in ActionScript 2.0. Which is Flash version 7.

Congratulations, you're a zealot.

Perhaps. But I would like to congratulate you on knowing a thing or two about Javascript. It's so hard to find a fellow JS coder that sometimes it feels like I'm the only one.

Re:Time to Learn How to Program (1)

suv4x4 (956391) | more than 7 years ago | (#18269268)

Funny, I was just mentioning that to another poster elsewhere in this thread. Perhaps my post was what gave you this idea? ;-)

Indeed! So I just pasted it from your response, in case you forgot what you were talking about exactly 47 seconds ago!

BTW, Flash implements most of ECMAScript 4.0 in ActionScript 2.0. Which is Flash version 7.

If you can say "most" when Flash 7 implemented loosely the class syntax at compiler time, on top of their extended prototypes engine, added types only as a compiler time check and no runtime support, didn't have regex, sealed classes, e4x, the machine types (int/uint/byte etc.), real namespaces (not the basic package hack of As2), event model, proper core runtime exceptions, method closures and probably a hundred other things which I can't recall immediately, then, YES, flash 7 had most of it.

But I bet Adobe (at the time MM) just thought "hey we had most of it in Flash 7, but we'll just dump all of this completely and rewrite the script engine from scratch in Flash 9, just for sheer fun".

Re:Time to Learn How to Program (0)

Anonymous Coward | more than 7 years ago | (#18280704)

Congratulations, you're an a-hole. btw, I enjoyed the post, and according to mod points, others did as well.

Re:Time to Learn How to Program (0)

Anonymous Coward | more than 7 years ago | (#18268340)

A JavaScript coder, advertising prototypes as proper "OOP"... telling us to learn how to program.

I can die now: I've seen everything.

Re:Time to Learn How to Program (1)

suv4x4 (956391) | more than 7 years ago | (#18268448)

What is this?

        function LightBulb(on)
        {
                this.on = on;

                this.isOn = function() { return this.on; }
                this.setOn = function(on) { this.on = on; }
        }

        var mybulb1 = new LightBulb(true);
        var mybulb2 = new LightBulb(false);

        alert(mybulb1.isOn()+" - "+mybulb2.isOn());


This is the wrong way to add methods to your "class", by adding pointless overhead to your constructor.
And this is the normal way:

function LightBulb() {...}

LightBulb.prototype = {isOn: function() {...}, setOn: function() {...}};

Re:Time to Learn How to Program (1)

AKAImBatman (238306) | more than 7 years ago | (#18268986)

If I'd shown them the Prototype method, I would have royally confused them. The inline method uses more memory, but it's much closer, syntactically, to what most people think of as an "object".

Ah well, at least someone's keeping me honest. :)

Re:Time to Learn How to Program (0)

Anonymous Coward | more than 7 years ago | (#18268698)

Tools...Options...Uncheck "Enable JavaScript".

All of your carefully written javascript is now broken, and nothing you can do will fix it.

Re:Time to Learn How to Program (1)

timster (32400) | more than 7 years ago | (#18268836)

If a Javascript program is written in the woods, but the user doesn't run it, is the Anonymous Coward an idiot?

Re:Time to Learn How to Program (1)

InsertCleverUsername (950130) | more than 7 years ago | (#18270544)

> If I may make a supposition, this occurs most often because programmers think
> they know how to program in Javascript, but don't have the first clue. That's

Amen. The situation out there is actually so bad, it boggles the mind how so many web developers continue to earn a paycheck. Want evidence? Turn on JS debugging/error messages in your browser (esp. IE) and spend a week or two battling the deluge of error dialogs before you turn it off again in disgust. If people can't be bothered to write robust JS, could they at least put in some sloppy try-catch blocks to make their crap less annoying? Or... You could recommend this (hilarious) "solution" to site visitors:
http://www.deerbrook.com/downloads/sysreqs/right_c lick_print11.htm [deerbrook.com]

If anything, we need more books like this.

Didn't Linus once say... (0)

Anonymous Coward | more than 7 years ago | (#18274326)

... that he could spot a good programmer from their style? What the hell is with your lightbulb example?

function newLight(){ return { state: false, toggle: function(){ this.state=!this.state; }, isOn: function(){ return this.state; } }; }
Thwack!

Javascript is easy (0)

Anonymous Coward | more than 7 years ago | (#18266990)

I used to hate javascript, not the language but the incompatible MSIE and Netscape bindings. As a language ECMAScript is so small and simple, I'm not sure it justifies a full book unless it's teaching basic programming.

The thing about javascript is that it's the de-facto scripting language, from serverside development with Java, and .NET to desktop widgets, flash and the Mozilla platform. I'm not saying it's a great scripting language but if I had to choose just one scripting language based on availability it'd be javascript.

Ironically for 10 years I've disabled javascript for web browsing and I'm not enabling it any time soon (Flame away)!

Re:Javascript is easy (1)

AKAImBatman (238306) | more than 7 years ago | (#18267052)

As a language ECMAScript is so small and simple, I'm not sure it justifies a full book unless it's teaching basic programming.

Typical.

If you know it so well, then please name at least two different methods of for creating your own objects in OOP-style Javascript. Ready? Go!

OOP style Javascript? (0)

Anonymous Coward | more than 7 years ago | (#18267444)

You mean one of the hacks for using class/methods or are you just talking about creating standard objects? Since all objects extend Object(), can I just extend that or one of the other builtins?

Re:OOP style Javascript? (1)

AKAImBatman (238306) | more than 7 years ago | (#18267596)

One of the "hacks" for class/methods, please. Of course, I already posted a couple when responding to another AC, so it's a bit too easy now. :-/

Re:OOP style Javascript? (0)

Anonymous Coward | more than 7 years ago | (#18268058)

As I thought, a trick question not just answered by:

var obj = new Object();
 
var obj2 = { };
With that in mind my dear Batman, here's a trick answer [mootools.net]

Re:OOP style Javascript? (1)

AKAImBatman (238306) | more than 7 years ago | (#18268164)

Actually, I was thinking more along the lines of:

1.

var x = {text: "Hello World", getText:function(){return this.text;}};
2.

function MyObject()
{
  var text = "Hello World!";
 
  this.getText = function() { return text; };
  this.setText = function(newtext) { text = newtext );
}
3.

function MyObject()
{
  var text = "Hello World!";
 
  this.getText = MyObject_getText;
  this.setText = MyObject_setText;
}
 
function MyObject_getText() { return text; };
function MyObject_setText(newtext) { text = newtext );
But congratulations on almost getting one right. (Insert eye rolling here.)

With that in mind my dear Batman, here's a trick answer

Well, there's a library for one of the alternate forms of inheritence. (A form which is unnecessary in most situations.) Yippee.

Re:OOP style Javascript? (0)

Anonymous Coward | more than 7 years ago | (#18268866)

You fucked it when you said "OOP" IMHO and you're not doing anything other than I did or the 2 methods of creating an array.

var a = new Array();
var a2 = [];
Or if we must have custom objects...

function obj(){}
obj.prototype.msg=function(){ return "Your terminology sucks!"; }
var obj2={ parent: new obj() };
obj2.getMsg=function(){ return this.parent.msg(); };
I asked for confirmation on what you were asking for (remember - prototype based languages are classless) so it was you who asked for hacks involving OOP inheritance. You know all this, you're just being a dick.

Re:OOP style Javascript? (0)

Anonymous Coward | more than 7 years ago | (#18273970)

You haven't replied so I guess this thread has died now but for me there's still fun to be had.

Well, there's a library for one of the alternate forms of inheritence. (A form which is unnecessary in most situations.) Yippee.


Most programmers (including you) conceptualize OOP using the class inheritance model, this is why it's being added to ECMAScript 4. Yippee yourself!

Re:Javascript is easy (0)

Anonymous Coward | more than 7 years ago | (#18268412)

In javascript, everything is an object.

Re:Javascript is easy (0)

Anonymous Coward | more than 7 years ago | (#18269254)

Hence my confusion with his redundant usage of "OOP-style" and then he really muddles his terminology when I ask for clarification :-/

 

Re:Javascript is easy (1)

MightyMartian (840721) | more than 7 years ago | (#18270196)

The language is no better and no worse than most scripting languages I've seen. I agree that its biggest problem isn't the language, but the platforms, which still have irritating (but probably inevitable) incompatibilities. In a way, it's not that much different than trying to code for multiple platforms in any language. We would all love to write our applications once, and have them magically work on every conceivable blend of hardware, operating system and software, but it's not going to happen, unless you want to go to something like Java (which is a whole other world of pain).

How to embed into HTML (0)

Anonymous Coward | more than 7 years ago | (#18267108)

Should I embed JavaScript into HTML by writing <script language="JavaScript"> or should I bow to the w3 consortium and write <script type="text/javascript"> ?

hope it helps (0, Offtopic)

mastershake_phd (1050150) | more than 7 years ago | (#18267120)

I no how to program in php and C (enough to do what I want). I just cant wrap my head around java.

Re:hope it helps (1)

Perseid (660451) | more than 7 years ago | (#18267188)

I find myself saying this a lot, but: Java is not JavaScript.

Feeding Trolls (1)

MicktheMech (697533) | more than 7 years ago | (#18267244)

no != know

Java != Javascript

I know I shouldn't, but it looks so hungry...

does it make me a sicko or a pedophile if (-1, Offtopic)

Anonymous Coward | more than 7 years ago | (#18267154)

if I fantasize about 4-ways with Emma Watson and the Olsen twins? I need /.'s opinion on this. (I'm 35 years old, which isn't THAT bad, I think banging Emma Watson is still probably socially acceptable in many parts of the world.)

y como podria? (0)

Anonymous Coward | more than 7 years ago | (#18267156)

perdonad el oftopic... pero... como podría suscribirme a una lista de distribución en la que me enviaran emails de artículos de mi interés? Por ejemplo cine, informática, cocina... No digo que me paguen por ello, pero si que me envien cosas interesantes. gracias y perdonad el oftopic! mi mail es consejoinf@ctima.uma.es espero vuestras respuestas.

Re:y como podria? (1)

DrJokepu (918326) | more than 7 years ago | (#18268224)

It's quite an interesting dialect of English language you speak... Hell, I don't understand a word of it! Seriously, if you'd like to post to an English-language forum, you should really try learn English. It's not that hard, even I managed to do it.

Be aware of the least common denominator (4, Insightful)

davidwr (791652) | more than 7 years ago | (#18267450)

I haven't RTFBook but any good web-development book must show how to code for graceful degradation. I hope this book does this.

Many web browsers do not support all features of JavaScript, and many that do allow users to disable certain features.

Handling these situations gracefully is essential to any good web site. Features such as JavaScript should be used to enhance a web site, not provide basic functionality.

Re:Be aware of the least common denominator (1)

truthsearch (249536) | more than 7 years ago | (#18267594)

To solve this problem I've found libraries such as prototype and scriptaculous most helpful. As long as they're used properly and mostly for visual enhancements they are cross-browser and degrade nicely. If a client asks for a rich text box, I usually choose implementations which gracefully fall back to plain text boxes.

But these days it's very hard to convince non-techies that web sites should often not require javascript for basic functionality. They see gmail or whatever and assume everyone on the net should now have such features.

Re:Be aware of the least common denominator (1)

GeckoX (259575) | more than 7 years ago | (#18267802)

There is but ONE rule you need to know to deal with ALL browser specific issues.

If in doubt, TEST the functionality before calling said functionality.

Do NOT insert code switches based on browser sniffing. Never ever ever.

It really is just that simple.

The only book everyone needs (1)

wumpus188 (657540) | more than 7 years ago | (#18267842)

is this [prototypejs.org] . Seriously.

Re:The only book everyone needs (0)

Anonymous Coward | more than 7 years ago | (#18267980)

So it's a library that makes it easier to muck with the DOM for people who don't know how to program Javascript? Brilliant.

Lightweight and unobtrusive? (1)

Keeper Of Keys (928206) | more than 7 years ago | (#18273246)

I wouldn't go down the prototype/scriptaculous route. Those libraries are powerful, but so is jQuery [jquery.com] , and it's much more lightweight and easier to learn. Fun, even.

If you want to understand unobtrusive javascripting (which is the only way to go really, unless you don't mind your site's content being invisible to search engines), PPK's book [quirksmode.org] is the best I've seen.

Still slashvertising books in 2007? (1)

xxxJonBoyxxx (565205) | more than 7 years ago | (#18268498)

The majority of JavaScript books are of limited help in this regard, because they focus on the language details, illustrated only with code snippets. Many readers would benefit more from instruction via working examples, which is the approach used by The Book of JavaScript.


Working examples - isn't that what the Internet is for? If I see something neat going on on someone's site, the first thing I generally do is to borrow the code. Also, why advertise this on SlashDot? If you didn't learn Javascript in about half a day 10 years ago, you're probably not welcome here anyway.

Re:Still slashvertising books in 2007? (1)

Todamont (1034534) | more than 7 years ago | (#18270804)

I started with javascript way back when win98 was the big new thing, and tried to support it for so long. Once I started doing advanced scripts, like animations or scrollpanels, the browser incompatibility issue became a SERIOUS problem. It's not a bad language, though, it has some interesting quirks that make programming with it fun and powerful. I could see game development with it, but you'd have to target one browser. This is total slashvertising.

JavaScipt interfaces (2, Interesting)

KickTheDog (583548) | more than 7 years ago | (#18268784)

Yeah.. JavaScript is so much more powerful that people think. I went about designing a javascript ASP.NET DatePicker I ended up in the world of Object Orients JS... its a little different but with concepts like prototypes its amazing to what extent you build interfaces that can do almost anything the desktop can do. Dainty Date is open source and can be downloaded here http://www.customcontrolfreak.com/ [customcontrolfreak.com]
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?