Learning JQuery 1.3
Michael J. Ross writes "Of all Web technologies, JavaScript may have the most checkered past — first heralded as a powerful object-oriented language for jazzing up Web pages, but later condemned as a source of spammy pop-up windows and horrid animations polluting websites everywhere. Yet during the past several years, Web designers and developers are increasingly using JavaScript unobtrusively, for client-site interactivity — as a supplement to server-side functionality, not a replacement, and built upon standards-compliant (X)HTML and CSS. As a result, the once-derided language is now enjoying a true resurgence in interest and use. This has been bolstered by the proliferation of JavaScript libraries, of which jQuery is clearly the front runner. Web programmers seeking to get up to speed on this exciting resource can turn to Learning jQuery 1.3: Better Interaction Design and Web Development with Simple JavaScript Techniques." Keep reading for the rest of Michael's review.
Learning jQuery 1.3
author
Jonathan Chaffer, Karl Swedberg
pages
444 pages
publisher
Packt Publishing
rating
9/10
reviewer
Michael J. Ross
ISBN
978-1847196705
summary
A detailed introduction to this popular JavaScript library.
Written by Jonathan Chaffer and Karl Swedberg — two veteran Web developers based in Grand Rapids, Michigan — Learning jQuery 1.3 was published on 13 February 2009, under the ISBN 978-1847196705, by Packt Publishing, which kindly provided to me a copy of the book for review. There is a publisher's Web page for the book, where readers can order print or PDF versions of the book (or both, at a sizable discount); contact Packt Publishing with questions or feedback; read more information about the book, the authors, and the table of contents; and download a free sample chapter (the fourth one, titled "Effects") in PDF format. Readers who want to follow along with the authors' discussion, should note that all of the sample code used in the book can be downloaded from its support page. There is also a link for reading the reported errata, of which there are eleven, as of this writing. (The erratum for page 40 is incorrectly listed twice.)
The book begins with a foreword by John Resig, the creator of jQuery. What follows is over 400 pages of information, organized into eleven chapters and four appendices, covering all of the major topics related to jQuery, after a quick-start chapter: selectors, events, effects, DOM manipulation, AJAX, tables, forms, shufflers and rotators, plug-ins, online resources, development tools, and closures. The book has all the ingredients to serve as a full introduction to jQuery for experienced Web programmers, because it assumes no prior knowledge of jQuery (or any other JavaScript libraries); but it does assume that the reader comprehends the basics of HTML, CSS, and JavaScript — thus not wasting time by teaching these prerequisites skills, as is attempted in some other Web programming books.
The first chapter may be brief, but it is sufficient to present the major features of jQuery, its advantages versus raw JavaScript, and a quick history of its various releases after it was first mentioned by John Resig in August 2005. In addition, the reader is shown where to obtain the library, how to add it to a Web page, and a few of its basic capabilities. In the given example, multiple HTML paragraph elements are styled using just three lines of code; yet the power of jQuery would have been demonstrated even better had the authors also shown the equivalent raw JavaScript needed to perform the same functionality.
The next four chapters present the basics of jQuery upon which everything that follows is built. Readers are introduced, in Chapter 2, to the jQuery syntax for accessing individual elements and groups of elements on a Web page, using the $() factory function, CSS selectors, and jQuery's own custom selectors. As with all of the chapters that follow, several examples are used to illustrate the core ideas. The ability to intercept and react to events on a Web page — such as a user clicking on a particular link — is an essential part of client-side interactivity, and is the topic of the third chapter. But first the groundwork is set by learning how to control when code is executed, how to utilize multiple scripts on a page, and how to use jQuery with other JavaScript libraries. Then a style switcher example is used to demonstrate the "this" keyword, shorthand event methods, and compound events, as well as event capturing, bubbling, objects, targets, propagation, delegation, namespacing, and other topics. Unfortunately, the screenshots are of little help, largely because the black-and-white images fail to show user feedback, such as green backgrounds on hover, and even bolded link text. Chapter 4, which covers jQuery effects, begins by explaining how to programmatically discover and save attribute values, for later use; then it explains how to hide and show HTML elements, fade them in and out, toggle their settings, create simple custom animations, invoke effects sequentially using queuing, and queue effects on different elements using callback functions. The fifth chapter shows how to easily add and remove elements and their attributes from the DOM, and even create a new DOM structure from scratch. Most of the sample code is well explained, except for the fourth line in the insertAfter() snippet on page 96, which is not clear at all. Also, the sample text that consumes the bulk of pages 98 and 99, should be replaced with something much shorter, partly because it would be easier to locate the "span" tags within the text. This chapter, like the previous one, concludes with a "nutshell" summary that is quite helpful — and would be even more so if it listed, next to each jQuery method, the corresponding page number.
Asynchronous JavaScript and XML (AJAX) is a combination of technologies that is seeing more widespread use every year, as developers discover the advantages of dynamic Web page interactivity without the reloading of the page each time, which of course slows down the process for the user. The sixth chapter shows how to utilize AJAX, from a jQuery perspective, with explanations and examples of the four major approaches that involve static data files, including a handy summary of when each approach would be most appropriate. Also explored are the dynamic AJAX strategies, including GET and POST requests. The authors should have mentioned that, in order to make functional the "E" and "F" dictionary entries in the example, the reader will need to load the index.html file using a Web server, and not as a static HTML file, so the calls to "e.php" and "f.php" will work. By the way, anyone confused by the reference to jQuery Reference Guide, on page 146, should be aware that it is the title of a book written by the same authors as this one.
With the seventh chapter, the authors transition from what they consider to be the tutorial portion of the book, and begin to demonstrate how the reader can utilize the earlier basics for improving Web page functionality — in this case, working with tables. The authors make good use of code snippets and screenshots to show how one can do table sorting, row striping, row highlighting, and other capabilities independent of — and in conjunction with — server-side equivalents. The subsequent chapter consists of a similar survey of jQuery goodness, but applied to forms — specifically: styling, client-side validation, auto-completion of search entry fields, and input masking (with an emphasis upon numbers). The sample HTML is a model of quality markup, except for the wrapping of checkbox input elements inside of label elements, which is noncanonical and can make it problematic to properly align all the checkboxes in a form vertically, for all browsers. Chapter 9, titled "Shufflers and Rotators," demonstrates how to create a rotator for RSS newsfeed headlines, and an image carousel featuring image enlargement with transition. Readers interested in testing out the sample code — and possibly even modifying it — should be aware that, for chapters 7 through 9, the sample code within the downloadable archive is not stored in chapter-named directories, but instead combined into an application, in the "bookstore" directory.
The last two chapters of the book are devoted to jQuery plug-ins — using those created by others, and developing one's own. In Chapter 10, to illustrate the high-level ideas, the authors focus on and recommend a number of specific plug-ins built for handling forms, advanced effects, widgets, tables, images, and charts, as well as some theming resources. In the subsequent chapter, the authors show how to develop plug-ins of varying complexity, including those that implement new global functions, implement new jQuery object methods, and extend the jQuery selector engine; the chapter wraps up with advice on how best to distribute newly-created plug-ins.
All of the chapters end with summaries, which, given the detailed and technical nature of the material within each chapter, do not add any value to the book, and could be excised without loss. The four appendices offer some valuable information: numerous online resources for readers seeking reference material; development tools for the most popular Web browsers; details on JavaScript closures; and a quick reference for the jQuery selector expressions and all of the methods. The weakest part of the book, the index, is inadequate — missing important terms, such as "animation," "callback," "iteration" (or "iterator"), and "toggling."
The following errata have yet to be listed on the book's support page: "Let[']s" (page 23), "page [is] loaded" (page 40), "if Normal was" (should read "if Normal were"; page 61), ", though" (should read "though,"; page 80), "user the $() factory function" (page 113), "slices with be" (page 283), and "though[,] there" (page 340). In the errata listed on the support page, the entry for parseFloat refers to page 74, but the error actually occurs once on page 69 and twice on pages 70, 71, and 79. In the six screenshots on pages 253 through 257, the shipping totals are incorrect. Nevertheless, the number of errata per page is far less than what is found in most computer books, especially those from Packt Publishing.
The generous amount of sample code should be quite helpful to the reader, because for most programmers, we learn best by example. However, there are many instances where a line of code is unnecessarily wrapped to a second line, even though there is plenty of room at the end of the first line to accommodate the portion of code forced down; pages 82 and 217 have glaring examples of this. The same premature wrapping is seen in some of the text, such as on pages 210 and 311.
The authors as a whole do an admirable job of explaining the central ideas. The explanations are generally clear, which is absolutely critical for a topic like jQuery that can be overwhelming to anyone unfamiliar with it — and not just as a result of the somewhat cryptic syntax (which admittedly is unavoidable), made worse by chaining and especially by the nesting of anonymous functions. Even a cursory glance through the book should make evident that the authors put a lot of effort into writing it, reflected not just in its substantial length, but also the number of examples they created for the book, and the functionality contained therein.
With its thorough coverage of key jQuery topics — from the basics to plug-in development — Learning jQuery 1.3 is an information-packed resource that can help Web developers learn how to take their JavaScript programming to the next level.
Michael J. Ross is a freelance website developer and writer.
You can purchase Learning jQuery 1.3 from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
The book begins with a foreword by John Resig, the creator of jQuery. What follows is over 400 pages of information, organized into eleven chapters and four appendices, covering all of the major topics related to jQuery, after a quick-start chapter: selectors, events, effects, DOM manipulation, AJAX, tables, forms, shufflers and rotators, plug-ins, online resources, development tools, and closures. The book has all the ingredients to serve as a full introduction to jQuery for experienced Web programmers, because it assumes no prior knowledge of jQuery (or any other JavaScript libraries); but it does assume that the reader comprehends the basics of HTML, CSS, and JavaScript — thus not wasting time by teaching these prerequisites skills, as is attempted in some other Web programming books.
The first chapter may be brief, but it is sufficient to present the major features of jQuery, its advantages versus raw JavaScript, and a quick history of its various releases after it was first mentioned by John Resig in August 2005. In addition, the reader is shown where to obtain the library, how to add it to a Web page, and a few of its basic capabilities. In the given example, multiple HTML paragraph elements are styled using just three lines of code; yet the power of jQuery would have been demonstrated even better had the authors also shown the equivalent raw JavaScript needed to perform the same functionality.
The next four chapters present the basics of jQuery upon which everything that follows is built. Readers are introduced, in Chapter 2, to the jQuery syntax for accessing individual elements and groups of elements on a Web page, using the $() factory function, CSS selectors, and jQuery's own custom selectors. As with all of the chapters that follow, several examples are used to illustrate the core ideas. The ability to intercept and react to events on a Web page — such as a user clicking on a particular link — is an essential part of client-side interactivity, and is the topic of the third chapter. But first the groundwork is set by learning how to control when code is executed, how to utilize multiple scripts on a page, and how to use jQuery with other JavaScript libraries. Then a style switcher example is used to demonstrate the "this" keyword, shorthand event methods, and compound events, as well as event capturing, bubbling, objects, targets, propagation, delegation, namespacing, and other topics. Unfortunately, the screenshots are of little help, largely because the black-and-white images fail to show user feedback, such as green backgrounds on hover, and even bolded link text. Chapter 4, which covers jQuery effects, begins by explaining how to programmatically discover and save attribute values, for later use; then it explains how to hide and show HTML elements, fade them in and out, toggle their settings, create simple custom animations, invoke effects sequentially using queuing, and queue effects on different elements using callback functions. The fifth chapter shows how to easily add and remove elements and their attributes from the DOM, and even create a new DOM structure from scratch. Most of the sample code is well explained, except for the fourth line in the insertAfter() snippet on page 96, which is not clear at all. Also, the sample text that consumes the bulk of pages 98 and 99, should be replaced with something much shorter, partly because it would be easier to locate the "span" tags within the text. This chapter, like the previous one, concludes with a "nutshell" summary that is quite helpful — and would be even more so if it listed, next to each jQuery method, the corresponding page number.
Asynchronous JavaScript and XML (AJAX) is a combination of technologies that is seeing more widespread use every year, as developers discover the advantages of dynamic Web page interactivity without the reloading of the page each time, which of course slows down the process for the user. The sixth chapter shows how to utilize AJAX, from a jQuery perspective, with explanations and examples of the four major approaches that involve static data files, including a handy summary of when each approach would be most appropriate. Also explored are the dynamic AJAX strategies, including GET and POST requests. The authors should have mentioned that, in order to make functional the "E" and "F" dictionary entries in the example, the reader will need to load the index.html file using a Web server, and not as a static HTML file, so the calls to "e.php" and "f.php" will work. By the way, anyone confused by the reference to jQuery Reference Guide, on page 146, should be aware that it is the title of a book written by the same authors as this one.
With the seventh chapter, the authors transition from what they consider to be the tutorial portion of the book, and begin to demonstrate how the reader can utilize the earlier basics for improving Web page functionality — in this case, working with tables. The authors make good use of code snippets and screenshots to show how one can do table sorting, row striping, row highlighting, and other capabilities independent of — and in conjunction with — server-side equivalents. The subsequent chapter consists of a similar survey of jQuery goodness, but applied to forms — specifically: styling, client-side validation, auto-completion of search entry fields, and input masking (with an emphasis upon numbers). The sample HTML is a model of quality markup, except for the wrapping of checkbox input elements inside of label elements, which is noncanonical and can make it problematic to properly align all the checkboxes in a form vertically, for all browsers. Chapter 9, titled "Shufflers and Rotators," demonstrates how to create a rotator for RSS newsfeed headlines, and an image carousel featuring image enlargement with transition. Readers interested in testing out the sample code — and possibly even modifying it — should be aware that, for chapters 7 through 9, the sample code within the downloadable archive is not stored in chapter-named directories, but instead combined into an application, in the "bookstore" directory.
The last two chapters of the book are devoted to jQuery plug-ins — using those created by others, and developing one's own. In Chapter 10, to illustrate the high-level ideas, the authors focus on and recommend a number of specific plug-ins built for handling forms, advanced effects, widgets, tables, images, and charts, as well as some theming resources. In the subsequent chapter, the authors show how to develop plug-ins of varying complexity, including those that implement new global functions, implement new jQuery object methods, and extend the jQuery selector engine; the chapter wraps up with advice on how best to distribute newly-created plug-ins.
All of the chapters end with summaries, which, given the detailed and technical nature of the material within each chapter, do not add any value to the book, and could be excised without loss. The four appendices offer some valuable information: numerous online resources for readers seeking reference material; development tools for the most popular Web browsers; details on JavaScript closures; and a quick reference for the jQuery selector expressions and all of the methods. The weakest part of the book, the index, is inadequate — missing important terms, such as "animation," "callback," "iteration" (or "iterator"), and "toggling."
The following errata have yet to be listed on the book's support page: "Let[']s" (page 23), "page [is] loaded" (page 40), "if Normal was" (should read "if Normal were"; page 61), ", though" (should read "though,"; page 80), "user the $() factory function" (page 113), "slices with be" (page 283), and "though[,] there" (page 340). In the errata listed on the support page, the entry for parseFloat refers to page 74, but the error actually occurs once on page 69 and twice on pages 70, 71, and 79. In the six screenshots on pages 253 through 257, the shipping totals are incorrect. Nevertheless, the number of errata per page is far less than what is found in most computer books, especially those from Packt Publishing.
The generous amount of sample code should be quite helpful to the reader, because for most programmers, we learn best by example. However, there are many instances where a line of code is unnecessarily wrapped to a second line, even though there is plenty of room at the end of the first line to accommodate the portion of code forced down; pages 82 and 217 have glaring examples of this. The same premature wrapping is seen in some of the text, such as on pages 210 and 311.
The authors as a whole do an admirable job of explaining the central ideas. The explanations are generally clear, which is absolutely critical for a topic like jQuery that can be overwhelming to anyone unfamiliar with it — and not just as a result of the somewhat cryptic syntax (which admittedly is unavoidable), made worse by chaining and especially by the nesting of anonymous functions. Even a cursory glance through the book should make evident that the authors put a lot of effort into writing it, reflected not just in its substantial length, but also the number of examples they created for the book, and the functionality contained therein.
With its thorough coverage of key jQuery topics — from the basics to plug-in development — Learning jQuery 1.3 is an information-packed resource that can help Web developers learn how to take their JavaScript programming to the next level.
Michael J. Ross is a freelance website developer and writer.
You can purchase Learning jQuery 1.3 from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Key, then, to learning JQuery this book is.
It's time to realise that Abble's products are the biggest abomination these days. Just say NO to the dumb iAbble way!!
Client side form handling is the browsers job.
Roll on HTML 5
I have been learning jquery lately. I am still uncomfortable about the functional programming paradigm. I really hate the way it creates highly indented code. At the end of some complex operations with several anonymous functions as arguments you end up with scads of )}: characters and it is easy to get lost in the indentation.
I looked into JQuery recently for a web project, and while it is really, really cool, it's pretty heavy if all you want is (say) a Calendar popup. I think JQuery is really useful if you are going to basically do a desktop-style application using Javascript, like a spreadsheet or other major application. If all you want is a few controls for standard web forms, JQuery is overkill and too slow to download. There are better individual choices.
Sometimes it's best to just let stupid people be stupid.
After years of doing UI development using Motif, then MFC and finally Swing and WinForms, I've ended up doing some web UI development for the past few years, mainly for business apps. It's simple enough to do, but I spend far too much of my time thinking "What the fuck?!?!" when using libraries like jQuery or YUI.
It's pretty bad that UI programming using C, C++, Java and even VB.NET was more enjoyable and productive than using JavaScript and jQuery.
With web UIs, we end up spending a whole lot of time getting around browser-specific problems, and many times it's just really awkward to bend our UI to the HTML or AJAX model. Often times, things that would have been really quick to do with Motif or even MFC ended up taking much longer to develop using HTML, JavaScript and jQuery.
And the UIs don't even look that good, too. We thankfully have some pretty good graphics designers working for us, and our web apps don't look bad, but they also don't look or feel as robust as native (or even pseudo-native like Swing) apps. Some of our users tell us that they found the old Motif apps easier to work with.
I really don't like the direction the craft is heading. We were making good progress up until Swing and WinForms, but then web development took over and it feels like we've made a serious regression. So I'm thinking about moving away from UI design and development, after 20+ years. There are other areas where they're going in the right direction. Unless I can find myself a job using Qt somewhere. That's the only toolkit that seems to be making sensible innovation these days.
Because you don't make classes and instances of the classes, you just use object.property notation, Javascript is NOT object-oriented. It is object-based.
THL phish sticks
Thanks to jQuery javascript just makes sense. You can refer to and interact with things around the pages so easily that you will laugh thinking about the old days, when scripters were getting mad to write cross-browser js... Book is good and easy to read-through in a single day for an already experienced jscripter.
slashwhat?
Once IE10?...11 comes out and all browsers have a standard JavaScript implementation all of these JavaScript frameworks will be borderline obsolete.
obj.addEventListener will be obj.addEventListener NOT
if(obj.attachEvent){...}else if(obj.addEventListener){...}else{...}
They will still have the convenience functions for Ajax, DragNDrop, and XPath, but once cross-browser annoyances are off the table the convenience factor becomes just another layer of abstraction.
I am unable to find comparisons of JQuery and MooTools.
If anyone has experience with both frameworks, could you please try to summarize the big differences and say which one you prefer?
Developers are using Javascript because they have no choice. Web development sucks, and Javascript is one of the reasons.
I have to say, that book cover reminds me of the day I had way too much pizza, and let's just say the pizza took upon itself to make a U-turn.
Table-ized A.I.
You have to understand, JavaScript isn't just a scripting language, and jQuery isn't just a library. They've basically become religions for some people, much more so than we've even seen for any other programming technology.
I think it has to do with the advocates of those technologies not having any real programming skills or experience. Since they've never been good enough to program in Qt or Swing or even Visual Basic, they can't see all of the horrid flaws that are prevalent throughout JS and jQuery.
Complete ignorance brings out the reaction that Anonymusing just subjected you to.
We don't use JavaScript where I work we use JQuery instead it's a lot more intuitive.
JQuery 1.4 alpha 2 just came out and the final version is scheduled for Thursday.
First post! (just in case I am...)
but that's not OO.
Why not? Data structures married to methods which operate on them, information hiding, data abstraction, encapsulation, modularity, inheritance, polymorphism.... if you can do all these things, why get hung up on whether this is focused around defining classes or deriving from other objects and functions?
Go ahead and show me is-a, has-a, and as-a inheritance in Javascript.
Maybe if you explain the class-based analogue (it's not apparent what you mean by "has-a," and near as I can tell "is-a" and "as-a" are the same thing in a language where you can apply duck-typing). Bonus if you can point out a type of problem without classes.
Tweet, tweet.
Oh for pity sake. "This feature isn't always on or available?
Two lines of php are sufficient to send a text/javascript and compress header, then a readfile of the pre-compressed jquery.js file, which you have prepared offline using the gzip command as a -c, will send the 11K file.
So, to answer my question: gzipping output is not available if the client browser is 10 years old or older.The browser will not know the difference unless it is pre-Netscape 4.x.
Also packer not jsminify.
If you're really hard on yourself, use non-parsed headers and cgi to send and the script becomes two echoes and a cat command.
A car HAS A carburetor.
http://en.wikipedia.org/wiki/Has-a
Has class-based OO education gotten so crazy that we end up doing this with class hierarchies rather than simple composition?
Tweet, tweet.
It is OO, but you did not make a new instance of a class, you made a new object. Apple is not a class, it is a closure.
I'm trying to stretch the definition of a closure to fit your statement and am not coming up with anything promising. I suppose you can look at an object as a scope of sorts and this or with as invoking that scope in the right context, but it doesn't seem to fit cleanly in my mind.
The semantics of the new keyword in JavaScript are the second most horrendous part of the spec.
It does what it says it does: creates a new object with a given prototype initialized with a constructor that's a function of the same name.
You're basically calling the closure with this bound to a new object which has Object as its prototype.
No, the type is object. The prototype is the "Apple" object (or, more precisely, the immediate link up the prototype chain is Apple and then ultimately Object).
Tweet, tweet.
But if you can't define new classes, you can't build object frameworks.
I believe you mean:
"if you can't define new classes, you can't build class hierarchies."
But there's ways of doing things when it comes to frameworks beyond setting up a class hierarchy.
Definitely not OO.
Even if you start with the axiom that OO means classes (a questionable assertion at best), and even if you don't like manually dealing with the prototype hierarchy as a proxy, it's been pretty convincingly demonstrated that you build classes onto standard javascript.
Tweet, tweet.
O'Reilly 2nd and 3rd editions of JavaScript explained everything you'd want to know about JavaScript but, like any other book on a language, didn't teach programming. JQuery might be convenient but it isn't likely to add value to properly written code. If you knew what you were doing with JavaScript in 1999 and maintained your library from that point forward, the only thing JQuery would add is the overhead of getting to know someone else's code.
Maybe this book is different; maybe it really is documentation. That is, information for programmers without the self-righteous crap or the marketing nonsense inherent to the Perl books from that same publisher. The shoulders that need repair after all the self-praise must give sports medicine something to write about. (Sigh). If only David Flanagan would write a Perl book.
Comparisons of JavaScript code with JQuery to code without JQuery -- and that omit consideration of the quality (or lack thereof) of the plain-old JavaScript -- shouldn't give JQuery any credibility. But they do, it seems. How ex- paste-up editors write code -- code from any programmer with little engineering prowess -- doesn't seem to be a basis for comparing any tool (sugar).
As David Flanagan wrote on his blog: "Good algorithms are better than clever code".
http://www.davidflanagan.com/2009/08/good-algorithms.html
As long as the folks I work with insist on using it I'll be stuck with it -- since I didn't maintain my libraries after 2003. Good thing for JQuery that the best of the programmers I work with thinks highly of it. Maybe its just me -- he likes the Perl texts, too.
Where does Dojo stand vis-a-vis jQuery?
What the hell is this kind of shit doing on Slashdot? People who use toy languages like CSS and JQuery are not 'programmers' or 'developers', they're simpletons who aren't intelligent enough to program in REAL languages like C, Assembler and BASH scripts. As such they don't belong on this site, and nor do their Fisher-Price 'tools'.
From the way you poo-poo classes
I'm not pooh-poohing classes in general; I'm happy to use classes and class hierarchies when they seem to fit the problem domain. The pooh-poohing I'm doing is the idea that you're not doing "real" object-oriented programming -- or that a language isn't an OOL -- if you don't have them built into the language.
you seem to be using OO as shorthand for both OOL and OOP, as if the two concepts were interchangeable. They're not.
I'm aware of the difference, having done OOP in even plain ol' C (definitely not the most OOL, but structs can hold function pointers and after that it's a matter of bookkeeping, which is why Strousup was able to more or less make the first implementation of C++ with a glorified C preprocessor). It's a good exercise which helps one appreciate the possibilities of a generally capable language as well as the work that other languages will do for you.
I'm not going to criticize the duck object paradigm, but it's definitely not the same as the OOP paradigm.
I suspect some confusion between static strong typing and classes. Some of the most dominant languages in the industry do things this way, which I think leads to the confusion, but it's only one possible mix of two largely orthogonal concerns.
But let's get to the meat of my comment:
And I was taught to be a real OOL, and not just a procedural language with pretensions, you have to support encapsulation (hiding the inner workings of the object from the code that uses it), polymorphism (the ability for various kinds of objects to all support the same method, so that user code doesn't need to know precisely what kind of object it's dealing with) and inheritance (the ability to define new object types based on an existing object types).
Sounds like a pretty good list to me.
All three of those criteria don't work without something resembling classes.
Sigh. And we were on a roll there. Let's go back to talking about Encapsulation, Polymorphism, and Inheritance.
Encapsulation: Javascript has methods, so it has OO encapsulation. That's my threshold, anyway. For some people it's different; they take the term to mean there exist means to ensure one can't examine the internal state of an object, that the language has some mechanism for enforcing privacy of member data. Personally, I think that many programmers overuse and abuse language-level enforcement mechanisms of this kind. If you're doing your design well, the methods you provide will be so convenient a developer won't even be curious about implementation and internal state. But there are some cases where enforcement really is important, and some people who aren't satisfied that it's OO if there's not a mechanism for it. So, in Javascript, you can do this with lexical scoping rules and closures:
function Example() {
var private = 0;
this.get = function () { return private; }
this.set = function (v) { private = v; }
}
e = new Example(); // the interpreter will have no idea what you're talking about, so it'll yield null // yields 5
e.set(5);
e.private
e.get();
You've got a simple object with a single private property that can be modified by a setter, retrieved with a getter, and touched no other way. And without being told or seeing the source, the programmer won't know whether Example objects do their storage in a closed-over scope, or on a remote server, or in a local database. Simple privacy-enforced encapsulation of concerns.
Polymorphism: if an object has a method, it'll respond to it. If not, you'll get an error/exception.
function Counter() {
var i = 0;
this.get = function () { return i++; }
}
function showObjValInTextBox(o) {
Tweet, tweet.
So any language that can implement objects is an OOL? So C is an OOL?
To quote my earlier post:
"having done OOP in even plain ol' C (definitely not the most OOL..."
So, no. I don't think of C as a particularly OOL. Perhaps minimally so because it provides a decent basis to get as OO as you like, but only minimally because it doesn't give you shortcuts for doing the three essentials we've discussed.
Javascript has convenient ways of doing all three built into the language, though, as I believe I've conclusively shown.
Assembly language?
Possibly more purely than anything else, as it's nothing but method calls on a few simple real objects. ;)
(Seriously, I'm happy to draw a bright line between 2GLs and 3GLs)
Tweet, tweet.