jQuery in Action
320
APPENDIX
JavaScript that you need to know but might not!
One of the great benefits that jQuery brings to our web applications is the ability to
implement a great deal of scripting-enabled behavior without having to write a
whole lot of script ourselves. jQuery handles the nuts-and-bolts details so that we
can concentrate on the job of making our applications do what they need to do!
implement a great deal of scripting-enabled behavior without having to write a
whole lot of script ourselves. jQuery handles the nuts-and-bolts details so that we
can concentrate on the job of making our applications do what they need to do!
For the first few chapters in this book, we only needed rudimentary JavaScript
skills to code and understand those examples. With the chapters on advanced
topics such as event handling, animations, and Ajax, we must understand a hand-
ful of fundamental JavaScript concepts to make effective use of the jQuery library.
You may find that a lot of things that you, perhaps, took for granted in JavaScript
(or took on blind faith) will start to make more sense.
topics such as event handling, animations, and Ajax, we must understand a hand-
ful of fundamental JavaScript concepts to make effective use of the jQuery library.
You may find that a lot of things that you, perhaps, took for granted in JavaScript
(or took on blind faith) will start to make more sense.
We're not going to go into an exhaustive study of all JavaScript concepts--
that's not the purpose of this book. The purpose of this book is to get us up and
running with effective jQuery in the shortest time possible. To that end, we'll con-
centrate on the fundamental concepts that we need to make the most effective use
of jQuery in our web applications.
running with effective jQuery in the shortest time possible. To that end, we'll con-
centrate on the fundamental concepts that we need to make the most effective use
of jQuery in our web applications.
The most important of these concepts centers around the manner in which
JavaScript defines and deals with functions, specifically the way in which func-
tions are first-class objects in JavaScript. What do we mean by that? Well, in order to
understand what it means for a function to be an object, let alone a first-class one,
we must first make sure that we understand what a JavaScript object itself is all
about. So let's dive right in.
tions are first-class objects in JavaScript. What do we mean by that? Well, in order to
understand what it means for a function to be an object, let alone a first-class one,
we must first make sure that we understand what a JavaScript object itself is all
about. So let's dive right in.
A.1 JavaScript Object fundamentals
The majority of object-oriented (
OO
) languages define a fundamental
Object
type of some kind from which all other objects are derived. Likewise, in Java-
Script, the fundamental
Script, the fundamental
Object
serves as the basis for all other objects, but that's
where the comparison stops. At its basic level, the JavaScript
Object
has little in
common with the fundamental object defined by its
OO
brethren languages.
At first glance, a JavaScript
Object
may seem like a boring and mundane item.
Once created, it holds no data and exposes little in the way of semantics. But
those limited semantics do give it a great deal of potential.
those limited semantics do give it a great deal of potential.
Let's see how.
A.1.1 How objects come to be
A new object comes into existence via the
new
operator paired with the
Object
constructor. Creating an object is as easy as
var shinyAndNew = new Object();