User: Password:
|
|
Subscribe / Log in / New account

Peters: Learning to write JavaScript

Now that she has started working at Mozilla, Stormy Peters decided she needed to write a web application. To that end, she started learning JavaScript. "Trouble shooting JavaScript was not always easy. If I was getting someone started with JavaScript, I'd set up their development environment and explain the tools first. Firebug, the Firefox Console and alerts ended up being my friends. Before I do more JavaScript development, I'll explore some more debugging tools." While the post is (obviously) JavaScript-specific, the approach she took could also be applied to learning other scripting languages.
(Log in to post comments)

Peters: Learning to write JavaScript

Posted Feb 11, 2011 5:39 UTC (Fri) by flewellyn (subscriber, #5047) [Link]

As someone who works with Javascript for a living, I have two suggestions for any newbie:

1) Firebug (http://getfirebug.com/). This debugger and web page inspector is your friend. If you are using Firefox, you want, no, NEED, this extension. If you aren't, you can use Firebug Lite (http://getfirebug.com/firebuglite), which works in all major browsers and supports most of the capabilities of Firebug.

2) JQUERY (http://jquery.com/)! This library makes working with web development so much easier, so much more powerful and flexible, and papers over most of the nasty DOM incompatibilities. Seriously, it's the best thing ever. Just the selectors alone are a huge boon.

Peters: Learning to write JavaScript

Posted Feb 11, 2011 6:14 UTC (Fri) by oever (subscriber, #987) [Link]

<a href="http://www.kdedevelopers.org/node/4367">Here</a> are some more tips. In summary, use JSLint, Closure Compiler and plenty of unit tests.

+1 to jQuery

Posted Feb 11, 2011 15:16 UTC (Fri) by dskoll (subscriber, #1630) [Link]

I couldn't agree more regarding jQuery. It's an amazing library that makes JavaScript tolerable, even fun.

Peters: Learning to write JavaScript

Posted Feb 13, 2011 7:28 UTC (Sun) by b7j0c (guest, #27559) [Link]

yes on firebug, not so fast on jquery

master javascript-the-language first, then try out jquery or yui to see the better way

at my employer, we're seeing lots of resumes for jquery coders who don't know anything about js itself. change the equation with yui or mootools and these guys are lost.

Peters: Learning to write JavaScript

Posted Feb 13, 2011 7:44 UTC (Sun) by flewellyn (subscriber, #5047) [Link]

Well, that's fair enough. You do need a good knowledge of how closures work to make good use of JQuery, for instance.

But in the case of someone like Stormy, who already knows programming? Probably not such a hard task to begin with.

Javascript is a functional language

Posted Feb 12, 2011 4:53 UTC (Sat) by hofhansl (guest, #21652) [Link]

IMHO it is crucial to understand that Javascript is a functional language and has more in common with Lisp or Schema then is a has with Java.

Designing Javascript like Java or C will *never* lead to good code.

Javascript is a functional language

Posted Feb 12, 2011 11:13 UTC (Sat) by storming (guest, #58723) [Link]

My first class in college was taught in Scheme, a version of Lisp. Perhaps that helped.

Javascript is a functional language

Posted Feb 13, 2011 7:32 UTC (Sun) by b7j0c (guest, #27559) [Link]

people who say javascript is a functional language are people who don't know what functional languages are

javascript is about as "functional" as perl. indeed i think perl has some functional-like features js doesn't have (map as a built-in, etc)

javascript is a decent small language that has a hodge-podge of half-baked functional features, as well as a hodge-podge of half-baked prototypical oo features.

Javascript is a functional language

Posted Feb 14, 2011 15:18 UTC (Mon) by rfunk (subscriber, #4054) [Link]

When people say Javascript is a functional language, they're primarily referring to the fact that functions can be assigned to variables, passed into other functions, and returned from functions, combined with support for variable closures. Javascript's "function" is equivalent to Lisp's "lambda".

Yes, Perl can be treated a functional language (Mark Jason Dominus's book "Higher-Order Perl" covers this), though it's rarely used that way. That's independent of whether Javascript is functional.

BTW, ECMAScript 5 (which most modern browsers support) actually does have map as a built-in. But even where map isn't built in, it's easy to add (partly because of those prototypal OO features, along with the basic functional features).

Take a look at Douglas Crockford's book, "JavaScript: The Good Parts".

Javascript is a functional language

Posted Feb 14, 2011 16:49 UTC (Mon) by nybble41 (subscriber, #55106) [Link]

> When people say Javascript is a functional language, they're primarily referring to the fact that functions can be assigned to variables, passed into other functions, and returned from functions, combined with support for variable closures.

That makes JavaScript a language with first-class and higher-order functions, not a functional language. "In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data" (http://en.wikipedia.org/wiki/Functional_programming). In what way does JavaScript avoid either state or mutation? Sure, you *can* do functional programming in JavaScript, but then again you can do functional programming in C if you try hard enough; most JS programs, like most C programs, are much more imperative than functional, making free use of side-effects. Compare this to Haskell or ML, where functional programming is clearly the dominant style and side-effects are rare.

People often assume that a language which borrows features from Common Lisp or Scheme must be functional "because Lisp and Scheme are functional", but actually Lisp and Scheme *aren't* functional languages; they're multi-paradigm, supporting both imperative and functional styles. JS is similar. Lisp and Scheme programmers tend to actually *use* the functional programming paradigm, however, and consider it good style to avoid side-effects where possible, while JS tends to be coupled with APIs (e.g. the HTML DOM) where side effects are impossible to avoid. In other words, the difference is in the communities which have grown up around each language, not their basic features.

Javascript is a functional language

Posted Feb 14, 2011 17:05 UTC (Mon) by rfunk (subscriber, #4054) [Link]

To me it seems meaningless to argue that a language is or is not functional based on whether most programmers using that language program according to Pure Functional Programming standards. (Most Javascript programmers don't even understand its object model, but that doesn't make it any less object-oriented than if they all did.) I don't care what most other programmers are doing with the language; I care what can be done with the language, and that's what people are talking about when they label a language as functional or OO or whatever.

Absolutely pure functional programming isn't very useful anyway; even the purest of functional languages have some facility for side-effects in order to be at all useful.

BTW, when talking about what people do with Javascript, keep in mind that these days many people use it on the server side, nowhere near the DOM.

Javascript is a functional language

Posted Feb 14, 2011 19:18 UTC (Mon) by nybble41 (subscriber, #55106) [Link]

You seem to have misunderstood my argument. I was not saying that a language becomes functional based on how it is used; I was saying that JavaScript, like Scheme and Lisp and many other languages, is multi-paradigm, no more functional than imperative, and that having closures-as-values and higher-order functions does not make a language functional--the "function" in "functional programming" refers to *mathematical* functions, and the associated traits of statelessness and immutability. It is the association with functional or imperative style which varies depending on the community and traditions which have grown up around the language, and which lead people to label Scheme as "functional" and JS as "imperative" despite their fundamental similarities, when neither label is truly appropriate.

Some languages, such as Haskell and ML, are functional by design, in that they discourage the use of state and mutation, and are specifically intended to model the side-effect-free evaluation of mathematical functions, with carefully delineated exceptions. JavaScript, Common Lisp and Scheme are not like these languages; they have mutation and state as first-class features.

If you really only "care [about] what can be done with the language", then C is a functional language, and object-oriented. It is certainly possible to write functional and OO code in C, although it may end up being a bit verbose.

Javascript is a functional language

Posted Feb 15, 2011 5:49 UTC (Tue) by b7j0c (guest, #27559) [Link]

please stop talking about functional programming, you have no idea what you are talking about

Javascript is a functional language

Posted Feb 15, 2011 5:46 UTC (Tue) by b7j0c (guest, #27559) [Link]

yes i've read "javascript: the good parts", and no, it has nothing to do with any of the points you are trying to make


Copyright © 2011, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds