JavaScript Programmer s Reference 1st ed. Edition Valentineinstant download
JavaScript Programmer s Reference 1st ed. Edition Valentineinstant download
or textbooks at https://ebookultra.com
_____ Follow the link below to get your download now _____
https://ebookultra.com/download/javascript-programmer-s-
reference-1st-ed-edition-valentine/
https://ebookultra.com/download/vbscript-programmer-s-reference-3rd-
ed-edition-adrian-kingsley-hughes/
https://ebookultra.com/download/excel-2007-vba-programmer-s-reference-
programmer-to-programmer-1st-edition-john-green/
https://ebookultra.com/download/visual-basic-2008-programmer-s-
reference-rod-stephens/
https://ebookultra.com/download/access-2007-vba-programmer-s-
reference-1st-edition-teresa-hennig/
Professional JavaScript Frameworks Prototype YUI ExtJS
Dojo and MooTools Wrox Programmer to Programmer 1st
Edition Leslie M. Orchard
https://ebookultra.com/download/professional-javascript-frameworks-
prototype-yui-extjs-dojo-and-mootools-wrox-programmer-to-
programmer-1st-edition-leslie-m-orchard/
https://ebookultra.com/download/javascript-a-beginner-s-guide-3rd-ed-
edition-pollock/
https://ebookultra.com/download/wpf-programmer-s-reference-windows-
presentation-foundation-with-c-2010-and-net-4-1st-edition-rod-
stephens/
https://ebookultra.com/download/javascript-creativity-exploring-the-
modern-capabilities-of-javascript-and-html5-1st-ed-edition-hudson/
https://ebookultra.com/download/beginning-javascript-3rd-ed-edition-
paul-wilton/
JavaScript Programmer s Reference 1st ed. Edition
Valentine Digital Instant Download
Author(s): Valentine, Thomas, Reid, Jonathan
ISBN(s): 9781430246299, 1430246294
Edition: 1st ed.
File Details: PDF, 2.82 MB
Year: 2013
Language: english
JavaScript Programmer’s
Reference
Jonathan Reid
Thomas Valentine
Apress
JavaScript Programmer’s Reference
Copyright © 2013 by Jonathan Reid and Thomas Valentine
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material
is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting,
reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material
supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the
purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the
Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from
Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are
liable to prosecution under the respective Copyright Law.
ISBN 978-1-4302-4629-9
ISBN 978-1-4302-4630-5 (eBook)
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion
and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified
as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither
the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may
be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
President and Publisher: Paul Manning
Lead Editor: Ben Renow-Clarke
Technical Reviewers: RJ Owen
Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel,
Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham,
Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft,
Gwenan Spearing, Matt Wade, Tom Welsh
Coordinating Editor: Christine Ricketts
Copy Editors: William McManus and Mary Bearden
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science +
Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing
web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text is available to readers at
www.apress.com. For detailed information about how to locate your book’s source code, go to
www.apress.com/source-code/.
For Mom and Dad, who have always been there for me.
—Jon Reid
Index .................................................................................................................................269
v
Contents
Summary .....................................................................................................................................23
vii
N CONTENTS
Operators.....................................................................................................................................29
Precedence .......................................................................................................................................................... 30
Variables......................................................................................................................................32
Declaring Variables in JavaScript ........................................................................................................................ 32
Understanding Variable Scope in JavaScript ....................................................................................................... 33
Managing Variables in JavaScript ....................................................................................................................... 35
Objects ........................................................................................................................................37
Inheritance........................................................................................................................................................... 37
Accessing Properties and Enumeration ............................................................................................................... 37
Creating Objects .................................................................................................................................................. 39
Arrays ..........................................................................................................................................41
Dynamic Length ................................................................................................................................................... 41
Accessing and Assigning Values.......................................................................................................................... 41
Creating Arrays .................................................................................................................................................... 42
Functions.....................................................................................................................................45
Function Declarations .......................................................................................................................................... 45
Function Expressions........................................................................................................................................... 46
Conditionals.................................................................................................................................51
if Statements ....................................................................................................................................................... 51
switch Statements ............................................................................................................................................... 52
viii
N CONTENTS
Loops ...........................................................................................................................................53
for Loops.............................................................................................................................................................. 53
for-in Loops ......................................................................................................................................................... 54
while Loops ......................................................................................................................................................... 55
do Loops .............................................................................................................................................................. 55
Summary .....................................................................................................................................56
ix
N CONTENTS
x
N CONTENTS
Boolean .....................................................................................................................................140
Boolean Methods ............................................................................................................................................... 141
Date ...........................................................................................................................................142
Date Methods .................................................................................................................................................... 142
Math ..........................................................................................................................................159
Math Properties ................................................................................................................................................. 160
Math Methods.................................................................................................................................................... 160
Number......................................................................................................................................166
Number Properties ............................................................................................................................................ 166
Number Methods ............................................................................................................................................... 166
RegExp ......................................................................................................................................168
RegExp Properties ............................................................................................................................................. 168
RegExp Methods ................................................................................................................................................ 170
String .........................................................................................................................................171
String Properties................................................................................................................................................ 172
String Methods .................................................................................................................................................. 172
Summary ...................................................................................................................................184
xi
N CONTENTS
if ................................................................................................................................................188
label...........................................................................................................................................189
return ........................................................................................................................................190
switch/case ...............................................................................................................................190
while..........................................................................................................................................192
with ...........................................................................................................................................192
Summary ...................................................................................................................................193
xii
N CONTENTS
Summary ...................................................................................................................................207
Summary ...................................................................................................................................268
Index .................................................................................................................................269
xiii
About the Authors
Jonathan Reid has been building web-based applications since 1996 and is passionate about creating awesome and
compelling user experiences on the web. He is a firm believer in user-centered creative processes and is an advocate
for standards and accessibility. Jon has a wide range of experience developing web applications, ranging from
genetic analysis software to cutting-edge advertising. Jon teaches courses in JavaScript, jQuery, and jQuery Mobile,
and has written extensively on all three topics. Jon bet his career on web technologies early on, and he is happy to
see his bet paying off.
Jon is an alumnus of the University of Colorado, Boulder, where he graduated with a degree in physics and
mathematics. He currently works as a Senior JavaScript Developer at Google, and lives in Sunnyvale, California with
his partner of 15 years. He occasionally tweets as @jreid01 and blogs even more occasionally at
webdev.dreamwidth.org.
Thomas Valentine lives in the small town of Selkirk, Manitoba, Canada on the shores of the Red River. His love of the
written word has shaped his career and life and will continue to do so for many years to come.
xv
About the Technical Reviewer
xvii
Introduction
JavaScript has seen a huge increase in popularity in the last decade. Originally used to create interactive web pages
and handle basic form validation, JavaScript is now the backbone of many complex web applications. As a result,
people who can program well with JavaScript are in high demand for a wide range of projects. If you want to work with
web technologies, you should know JavaScript.
This book aims to provide both a complete reference for JavaScript and to cover the fundamentals of the
language. Our overall goal was to cover all the topics you need to work with JavaScript in projects of any size.
Overview
This book is divided into two sections. The first section is devoted to teaching the basics of JavaScript and its related
technologies. The second section is devoted to reference.
r Chapter 1 is aimed at the programmer who is coming to JavaScript from another language.
JavaScript is a much more dynamic language than most of the common languages, and
moving to JavaScript from those languages can present special challenges. First we cover what
JavaScript is and how it came to be, and then we dive right into the three main challenges that
programmers of other languages encounter: JavaScript’s object inheritance and lack of classes,
its rules for scoping, and its dynamic typing. All of these features work quite differently in
JavaScript than they do in other languages, and we want to get into them immediately. We wind
up the chapter by providing some common patterns in JavaScript that use what we have learned.
r Chapter 2 is an overall reference for the JavaScript language. We start at the beginning, with
JavaScript’s lexical structure, and quickly move into its operators, how it handles variables,
JavaScript’s take on objects, arrays, and functions. We wind up the chapter by going
over JavaScript’s flow control statements. Chapter 2 covers some of the things mentioned in
Chapter 1 in more detail. Together they form a solid introduction to the language, all the way
from the basics to intermediate concepts like closures.
xix
Exploring the Variety of Random
Documents with Different Content
in any community is the best judge of its interests; whilst it is even
less certain, if it did know these interests, that it would necessarily
and invariably follow them. In almost every collection of men the
intelligent few know better what is for the common interest than the
ignorant many; and it is rare indeed to see communities or
individuals pursuing their interest steadily even when they perceive it
clearly. It would, perhaps, be more reconcilable to reason to say that
the intellect of a community should govern a community; but this
assertion is also open to objection, since a small number of
intelligent men might govern for their own interest, and not for the
interest of the society they represented. In short, though it is easy to
see that the science of government does not consist in giving power
to the greatest number, but in giving it to the most intelligent, and
making it for their interest to govern for the interest of the greatest
number; still, every day teaches us that good government is rather a
thing relative than a thing absolute; that all governments have good
mixed with evil, and evil mixed with good; and that the statesman’s
task, as is beautifully demonstrated by Montesquieu, is, not to
destroy an evil combined with a greater good, nor to create a good
accompanied with a greater evil; but to calculate how the greatest
amount of good and the least amount of evil can be combined
together. Hence it is, that the best governments with which we are
acquainted seem rather to have been fashioned by the working hand
of daily experience, than by the artistic fingers of philosophical
speculation.
Nevertheless, the theory, that the good of the greatest number in
any community ought to be the object which its government should
strive to attain, and the maxim, that the interest and happiness of
every unit in a community are to be treated as a portion of the
interest and happiness of the whole community, are humanizing
precepts, and have, through the influence of Mr. Bentham and of his
disciples, produced, within my own memory, a considerable change
in the public opinion of England.
Mr. Bentham’s name, then, is far more above the scoff of his
antagonists than below the enthusiasm of his disciples; and it is in
this spirit, and with a becoming respect, that Sir James Mackintosh
treats the philosopher while he combats his philosophy.
IX.
X.
XI.
I.
II.
III.
At this period Cobbett married. Nobody has left us wiser
sentiments or pithier sentences on the choice of a wife. His own, the
daughter of a sergeant of artillery, stationed like himself at New
Brunswick, had been selected at once. He had met her two or three
times, and found her pretty; beauty, indeed, he considered
indispensable, but beauty alone would never have suited him.
Industry, activity, energy, the qualities which he possessed, were
those which he most admired, and the partner of his life was fixed
upon when he found her, one morning before it was distinctly light,
“scrubbing out a washing-tub before her father’s door.” “That’s the
girl for me,” he said, and he kept to this resolution with a fortitude
which the object of his attachment deserved and imitated.
The courtship was continued, and the assurance of reciprocated
affection given; but before the union of hands could sanctify that of
hearts, the artillery were ordered home for England. Cobbett, whose
regiment was then at some distance from the spot where his
betrothed was still residing, unable to have the satisfaction of a
personal farewell, sent her 150 guineas, the whole amount of his
savings, and begged her to use it—as he feared her residence with
her father at Woolwich might expose her to bad company—in
making herself comfortable in a small lodging with respectable
people until his arrival. It was not until four years afterwards that he
himself was able to quit America, and he then found the damsel he
had so judiciously chosen not with her father, it is true, nor yet
lodging in idleness, but as servant-of-all-work for five pounds a year,
and at their first interview she put into his hands the 150 guineas
which had been confided to her—untouched. Such a woman had no
ordinary force of mind; and it has been frequently asserted that he
who, once beyond his own threshold, was ready to contend with
every government in the world, was, when at home, under what has
been appropriately called the government of the petticoat.
Cobbett’s marriage took place on the 3rd of February, 1792; that
is, about ten weeks after his discharge; but having in March brought
a very grave charge against some of the officers of his regiment,
which charge, when a court-martial was summoned, he did not
appear to support, he was forced to quit England for France, where
he remained till September, 1792, when he determined on trying his
fortune in the United States.
IV.
V.
VI.
VII.
VIII.
Part II.
FROM JUNE 1ST, 1800, TO MARCH 28TH, 1817, WHEN, HAVING
ALTOGETHER CHANGED HIS POLITICS, HE RETURNS TO AMERICA.
Starts a paper, by title The Porcupine, which he had made famous in America.—
Begins as a Tory.—Soon verges towards opposition.—Abandons Porcupine and
commences Register.—Prosecuted for libel.—Changes politics, and becomes radical.
—Prosecuted again for libel.—Convicted and imprisoned.—Industry and activity
though confined in Newgate.—Sentence expires.—Released.—Power as a writer
increases.—Government determined to put him down.—Creditors pressing.—He
returns to the United States.
I.
The space Cobbett filled in the public mind of his native land was at
this time, 1800, considerable. Few, in fact, have within so brief a
period achieved so remarkable a career, or gained under similar
circumstances an equal reputation. The boy from the plough had
become the soldier, and distinguished himself, so far as his birth and
term of service at that time admitted, in the military profession; the
uneducated soldier had become the writer; and, as the advocate of
monarchical principles in a Republican state, had shown a power and
a resolution which had raised him to the position of an antagonist to
the whole people amongst whom he had been residing. There was
Cobbett on one side of the arena, and all the democracy of
democratic America on the other!
He now returned to the Old World and the land for which he had
been fighting the battle. His name had preceded him. George III.
admired him as his champion; Lord North hailed him as the greatest
political reasoner of his time (Burke being amongst his
contemporaries); Mr. Windham—the elegant, refined, classical, manly,
but whimsical Mr. Windham—was in raptures at his genius; and
though the English people at this time were beginning to be a little
less violent than they had been in their hatred of France and America,
the English writer who despised Frenchmen and insulted Americans,
was still a popular character in England.
Numerous plans of life were open to him; that which he chose was
the one for which he was most fitting, and to which he could most
easily and naturally adapt himself. He again became editor of a public
paper, designated by the name he had rendered famous, and called
The Porcupine.
The principles on which this paper was to be conducted were
announced with spirit and vigour. “The subjects of a British king,” said
Cobbett, “like the sons of every provident and tender father, never
know his value till they feel the want of his protection. In the days of
youth and ignorance I was led to believe that comfort, freedom, and
virtue were exclusively the lot of Republicans. A very short trial
convinced me of my error, admonished me to repent of my folly, and
urged me to compensate for the injustice of the opinion which I had
conceived. During an eight years’ absence from my country, I was not
an unconcerned spectator of her perils, nor did I listen in silence to
the slander of her enemies.
“Though divided from England by the ocean, though her gay fields
were hidden probably for ever from my view, still her happiness and
her glory were the objects of my constant solicitude. I rejoiced at her
victories, I mourned at her defeats; her friends were my friends, her
foes were my foes. Once more returned, once more under the
safeguard of that sovereign who watched over me in my infancy, and
the want of whose protecting arm I have so long had reason to
lament, I feel an irresistible desire to communicate to my countrymen
the fruit of my experience; to show them the injurious and degrading
consequences of discontent, disloyalty, and innovation; to convince
them that they are the first as well as happiest of the human race,
and above all to warn them against the arts of those ambitious and
perfidious demagogues who could willingly reduce them to a level
with the cheated slaves, in the bearing of whose yoke I had the
mortification to share.”
II.
The events even at this time were preparing, which in their series
of eddies whirled the writer we have been quoting into the midst of
those very ambitious and perfidious demagogues whom he here
denounces. Nor was this notable change, under all the circumstances
which surrounded it, very astonishing. In the first place, the party in
power, after greeting him on his arrival with a welcome which,
perhaps, was more marked by curiosity than courtesy, did little to
gratify their champion’s vanity, or to advance his interests. With that
indifference usually shown by official men in our country to genius, if
it is unaccompanied by aristocratical or social influence, they allowed
the great writer to seek his fortunes as he had sought them hitherto,
pen in hand, without aid or patronage.
In the second place, the part which Mr. Pitt took on the side of
Catholic emancipation was contrary to all Cobbett’s antecedent
prejudices: and then Mr. Pitt had treated Cobbett with coolness one
day when they met at Mr. Windham’s. Thus a private grievance was
added to a public one.
The peace with France—a peace for which he would not illuminate,
having his windows smashed by the mob in consequence—disgusted
him yet more with Mr. Addington, whose moderate character he
heartily despised; and not the less so for that temporising
statesman’s inclination rather to catch wavering Whigs than to satisfy
discontented Tories. These reasons partly suggested his giving up the
daily journal he had started (called, as I have said, The Porcupine),
and commencing the Weekly Political Register, which he conducted
with singular ability against every party in the country. I say against
every party in the country; for, though he was still, no doubt, a stout
advocate of kingly government, he did not sufficiently admit, for the
purposes of his personal safety, that the king’s government was the
king’s ministers. Thus, no doubt to his great surprise, he found that
he, George III.’s most devoted servant, was summoned one morning
to answer before the law for maliciously intending to move and incite
the liege subjects of his Majesty to hatred and contempt of his royal
authority.
The libel made to bear this forced interpretation was taken from
letters in November and December, 1803, signed “Juverna,” that
appeared in the Register, and were not flattering to the government
of Ireland.
III.
The first tilt which he made from the new side of the ring where he
had now taken his stand was against Mr. Pitt—whom it was not
difficult towards the close of his life to condemn, for the worst fault
which a minister can commit—being unfortunate. Cobbett’s next
assault—on the demand of the Whigs for an increase of allowance to
the king’s younger sons—was against Royalty itself, its pensions,
governorships, and rangerships, which he called “its cheeseparings
and candle-ends!” Some Republicans on the other side of the Atlantic
must have rubbed their spectacles when they read these effusions;
but the editor of the Register was indifferent to provoking censure,
and satisfied with exciting astonishment. Besides, we may fairly
admit, that, when the King demanded that his private property in the
funds should be free from taxation (showing he had such property),
and at the same time called upon the country to increase the
allowances of his children, he did much to try the loyalty of the
nation, and gave Cobbett occasion to observe that a rich man did not
ask the parish to provide for his offspring. “I am,” said he, “against
these things, not because I am a Republican, but because I am for
monarchical government, and consequently adverse to all that gives
Republicans a fair occasion for sneering at it.”
In the meantime his periodical labours did not prevent his
undertaking works of a more solid description; and in 1806 he
announced the “Parliamentary Register,” which was to contain all the
recorded proceedings of Parliament from the earliest times; and was
in the highest degree useful, since the reader had previously to wade
through a hundred volumes of journals in order to know anything of
the history of the two Houses of Parliament. These more serious
labours did not, however, interfere with his weekly paper, which had a
large circulation, and, though without any party influence (for Cobbett
attacked all parties), gave him a great deal of personal power and
importance. “It came up,” says the author, proudly, “like a grain of
mustard-seed, and like a grain of mustard-seed it has spread over the
whole civilised world.” Meanwhile, this peasant-born politician was
uniting rural pursuits with literary labours, and becoming, in the
occupation of a farm at Botley, a prominent agriculturist and a sort of
intellectual authority in his neighbourhood. From this life, which no
one has described with a pen more pregnant with the charm and
freshness of green fields and woods, he was torn by another
prosecution for libel.
V.
VI.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com