Instant Access to Pro Javascript Design Patterns 1st Edition Ross Harmes ebook Full Chapters
Instant Access to Pro Javascript Design Patterns 1st Edition Ross Harmes ebook Full Chapters
com
https://ebookname.com/product/pro-javascript-design-
patterns-1st-edition-ross-harmes/
OR CLICK HERE
DOWLOAD NOW
https://ebookname.com/product/learning-javascript-design-patterns-
addy-osmani/
ebookname.com
https://ebookname.com/product/pro-html5-and-css3-design-patterns-1st-
edition-michael-bowers/
ebookname.com
https://ebookname.com/product/learning-javascript-design-patterns-a-
javascript-and-react-developer-s-guide-2nd-edition-adnan-osmani/
ebookname.com
https://ebookname.com/product/creativity-in-english-as-a-lingua-
franca-idiom-and-metaphor-1st-edition-marie-luise-pitzl/
ebookname.com
The Effects of Early Social Emotional and Relationship
Experience on the Development of Young Orphanage Children
Monographs of the Society for Research in Child
Development 1st Edition The St. Petersburg-Usa Orphanage
https://ebookname.com/product/the-effects-of-early-social-emotional-
Research Team
and-relationship-experience-on-the-development-of-young-orphanage-
children-monographs-of-the-society-for-research-in-child-
development-1st-edition-the-st-petersb/
ebookname.com
https://ebookname.com/product/lacey-wells-and-quick-reconstructing-
criminal-law-text-and-materials-law-in-context-4th-edition-celia-
wells/
ebookname.com
https://ebookname.com/product/language-from-the-body-iconicity-and-
metaphor-in-american-sign-language-1st-edition-sarah-f-taub/
ebookname.com
https://ebookname.com/product/modern-capital-theory-first-edition-
dewey/
ebookname.com
Northern Cheyenne Ledger Art by Fort Robinson Breakout
Survivors Denise Low
https://ebookname.com/product/northern-cheyenne-ledger-art-by-fort-
robinson-breakout-survivors-denise-low/
ebookname.com
™
Pro JavaScript
Design Patterns
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
v
Contents
■CHAPTER 2 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
What Is an Interface? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Benefits of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Drawbacks of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
How Other Object-Oriented Languages Handle Interfaces. . . . . . . . . . . . . 12
Emulating an Interface in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Describing Interfaces with Comments . . . . . . . . . . . . . . . . . . . . . . . . . 14
Emulating Interfaces with Attribute Checking . . . . . . . . . . . . . . . . . . . 16
Emulating Interfaces with Duck Typing . . . . . . . . . . . . . . . . . . . . . . . . 17
The Interface Implementation for This Book . . . . . . . . . . . . . . . . . . . . . . . . . 18
The Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
When to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
How to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Example: Using the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Patterns That Rely on the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
vii
viii ■CONTENTS
■CHAPTER 4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Why Do You Need Inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Prototype Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The extend Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Asymmetrical Reading and Writing of Inherited Members . . . . . . . . 46
The clone Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Comparing Classical and Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . 49
Inheritance and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Mixin Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Example: Edit-in-Place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Using Mixin Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
When Should Inheritance Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
■CHAPTER 6 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Structure of a Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Building a Chainable JavaScript Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Using Callbacks to Retrieve Data from Chained Methods . . . . . . . . . . . . . 89
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
About the Authors
xv
About the Technical Reviewer
■SIMON WILLISON is a consultant on client- and server-side web development and a cocreator
of the Django web framework. Simon’s interests include OpenID, unobtrusive JavaScript,
and rapid application development. Before going freelance, Simon worked on Yahoo!’s
Technology Development team, and prior to that at the Lawrence Journal-World, an award-
winning local newspaper in Kansas. Simon maintains a popular web development weblog
at http://simonwillison.net/.
xvii
Acknowledgments
T hanks to our intrepid technical reviewer, Simon Willison, without whom this book would be
much less accurate, practical, and interesting. He worked tirelessly to provide amazing feedback
for each and every chapter.
Thanks to our colleagues and coworkers who took the time to wade through the early drafts
and provide notes and corrections. Dave Marr and Ernest Delgado in particular went above and
beyond and were instrumental in finding typos, technical errors, and poorly worded sentences.
Also, thanks to Lindsey Simon and Robert Otani, each of whom supported us by providing
ceaseless JavaScript humor.
Thanks to our friends and family, who stood by patiently while we bored them to death
with our endless tales of writing and incomprehensible technical minutiae. Your support kept
us going.
And lastly, we both wish to give our sincerest thanks to the people at Apress who made
this book a reality. The patience, understanding, and perseverance of Chris Mills, Tom Welsh,
Dominic Shakeshaft, Richard Dal Porto, and Jennifer Whipple deserve special recognition and
won’t be forgotten.
xix
Introduction
J avaScript is at a turning point. The language and those who program with it have matured.
People are starting to realize that it is a complex subject, worthy of further study.
Design patterns have been used in programming for years. They were first formally docu-
mented in Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
(affectionately known as the Gang of Four) and have been applied to countless object-oriented
languages. Part of the appeal of design patterns is that they can be used uniformly over many
different languages and syntaxes. The basic structure stays the same; only the details change.
It is fairly easy, for instance, to take a pattern implemented in Java and convert it to C++.
The same cannot be said of JavaScript. While all of the same capabilities exist, they are
often not official parts of the language and must be emulated through obscure tricks and
unintuitive techniques. Over the years, people have discovered ways of using the language to
accomplish tasks never imagined by its creators. We must do likewise to implement common
object-oriented features.
This book collects and documents those tricks and techniques. In the first part, we create
a base of object-oriented features that we can build upon to implement specific design patterns.
The second part deals with specific design patterns and how they can be used in the JavaScript
language.
We took great pains to make the examples in each chapter as practical as possible. We
tried to list some of the most common tasks performed by JavaScript programmers, and then
used design patterns to make them more modular, efficient, and easily maintained. When we
do venture into more theoretical examples, it is done to illustrate a specific point. We know
that at the end of the day, the value of this book will be judged by its relevance to your every-
day tasks and projects.
We hope you enjoy this book. JavaScript is an incredibly complex and flexible language,
and one that is well-suited to experimentation. Play around with any of our code examples.
Let us know if you find a novel way of implementing a pattern, or a new use for an old tech-
nique. More information and downloadable code examples can be found at the book’s
website, http://jsdesignpatterns.com, and at the Apress website, http://www.apress.com.
xxi
Random documents with unrelated
content Scribd suggests to you:
house.
And then, when it grew dark, Uncle Wiggily called together ten
thousand firefly-lightning bugs, and they flittered and fluttered about
the porch, on which the boy had been taken after supper. The fireflies
made pinwheels of themselves, they went up like skyrockets, they
leaped about in bunches like the balls from Roman candles and finally,
when it was time to go to bed, they took hold of each others' legs
and, clinging together, spelled out:
"Oh, it's just like real fireworks!" cried the happy boy.
"I'm glad he liked it!" said Uncle Wiggily, as he hopped home to his
hollow stump bungalow.
So if the pussy cat doesn't claw the tail off the letter Q and make it
look like a big, round O, I'll tell you next about Uncle Wiggily and the
little boy's skates.
STORY XIII
UNCLE WIGGILY AND THE SKATES
There was once a little boy to whom Santa Claus brought a pair of
skates at Christmas. And, of course, that boy, as soon as he saw the
shiny, steel runners, wished that the pond would freeze over so that he
might try his new playthings.
"When do you s'pose there'll be skating?" he asked his mother again
and again, for, as yet, there was only a "skim" of ice on the pond.
"Oh, pretty soon," his mother would answer. "You mustn't go skating
when the ice is too thin, you know. If you did you would break through,
into the cold water."
"And that would spoil my skates, wouldn't it?" asked the boy.
"Yes, but besides that you might be drowned, or catch cold and be very
ill," Mother said. "So keep off the ice with your new skates until the
pond has frozen good and thick."
"Yes'm, I will," promised the little boy, and, really, he meant to keep his
word. But as the days passed, and the weather was not quite cold
enough to freeze thick ice, the little boy became tired of waiting.
Every chance he had, after school, he would go down to the edge of the
pond, and throw stones on the ice to see how thick it was. Often the
stones would break through, and fall into the cold, black water with a
"thump!" Then the boy would know the ice was not thick enough.
"I don't want to fall through like a stone," he would say, and back to his
house he would go with his new skates dangling and jingling at his
back, over which they were hung by a strap.
But one day, when the boy threw a large stone on the ice of the pond,
instead of breaking through, the rock only made a dent and stayed
there.
"Oh, hurray!" cried the boy. "I guess it's strong enough to hold me now!
I'm going skating!"
However, first he started to walk on the edge of the ice near the shore,
and when he did so, and heard cracking sounds, he jumped quickly
back.
"I guess I'd better not try it yet," said the boy to himself. "I'll wait a little
while until it freezes harder."
So he sat down by the edge of the pond to wait for the ice to freeze
harder. But as he sat there, and saw how white and shiny it was, and as
he looked at his new skates, which he had only put on in the house, that
boy couldn't wait another minute.
He walked along the shore a little farther, to a place where the ice
seemed more hard and shiny and there, after throwing some stones,
and venturing out a little way, finding that there was no cracking sound,
the little boy made up his mind to try to skate. There was no one else
on the pond—no other boys and girls, and it was a bit lonesome. But
the boy was so eager to try his new skates that he did not think of this.
Down he sat on the ground, and began putting on his Christmas skates.
And it was just about this time that Nurse Jane Fuzzy Wuzzy, Uncle
Wiggily's muskrat lady housekeeper, happened to look out of the
window of the hollow stump bungalow. The bunny's bungalow was so
hidden in the woods, near the pond, that few boys or girls ever saw the
queer little house. But Uncle Wiggily could see them, as they came to
the woods winter and summer, and often he was able to help them.
"Well, I declare!" exclaimed Nurse Jane, as she looked out of the
window a second time.
"What's the matter?" asked Uncle Wiggily, who was just finishing his
breakfast of lettuce bread and carrot coffee, with some turnip
marmalade.
"Why, there's a boy—a real boy and not one of the animal chaps—
getting ready to go skating!" said the muskrat lady, for she could see
the boy putting on his skates.
"That ice isn't thick enough for real boys or girls to skate on," the bunny
gentleman said. "It would be all right for Sammie Littletail, or Johnnie or
Billie Bushytail, but real boys are too heavy—much heavier than my
nephew Sammie the rabbit, or than the bushytail squirrel chaps."
"Well, this boy is going on all the same," cried Nurse Jane. "And I know
he'll break through, and he'll frighten his mother into a conniption fit!"
"That will be too bad!" exclaimed Uncle Wiggily, as he wiped a little of
the turnip marmalade off his whiskers, where it had fallen by mistake. "I
must try to save him if he does fall in!"
"It would be better to keep him from going on the ice," spoke Nurse
Jane. "Safety first, you know!"
"If I could speak boy language I'd hop down there and tell him the ice is
too thin," answered Uncle Wiggily. "But though I know what the boys
and girls say, I cannot, myself, speak their talk. However, I think I know
a way to save this boy, if he happens to break through the ice."
"Well, he's almost sure to break through," declared Miss Fuzzy Wuzzy,
"so you'd better hurry."
"No sooner said than done!" exclaimed Uncle Wiggily, and, catching up
his red, white and blue striped rheumatism crutch, and putting on his fur
cap (for the day was cold), away the bunny hopped from his hollow
stump bungalow.
Instead of going to the place where the boy, with his skates fastened on
his shoes, was about to try the ice, the bunny gentleman went to the
house of some friends of his. The house would seem queer to you, for
all it looked like was a pile of sticks half buried in the frozen pond.
But in this house lived a family of beavers—queer animals whose fur is
so warm and thick that they can swim in ice water and not feel chilly. In
fact the beavers had to dive down under the ice and water to get into
their winter home.
"Are Toodle and Noodle in the house?" asked Uncle Wiggily, as he
reached the stick-house. On shore, not far from it, was Grandpa
Whackum, the old beaver gentleman, with his broad, flat tail.
"Why, yes, Toodle and Noodle are inside," answered Grandpa Whackum.
"Shall I call them out?"
"If you please," spoke Uncle Wiggily. "I want them to come and help me
save a boy who, I think, is going to break through the thin ice with his
new skates."
"That will be too bad!" exclaimed Grandpa Whackum. Then with his
broad tail he pounded or "whacked" on the ground, and soon up
through a hole in the ice came swimming Toodle and Noodle Flat-Tail,
the two beaver boys.
"Oh, hello, Uncle Wiggily!" they called. "We're glad to see you!"
"Hello!" answered the bunny gentleman. "Will you come with me, and
help save a real boy?"
"Of course," said Toodle, shaking off some ice water from his fur coat.
"He won't try to catch us, will he?" asked Noodle.
"I think not," the bunny gentleman replied. "If what I think is going to
happen, does really happen, that boy will be too surprised to catch
anything but a cold! Come along, beaver chaps!"
So Toodle and Noodle, wet and glistening from having dived out of their
house, and down under water to come up through the hole in the ice,
followed Uncle Wiggily. The sun and wind soon dried their fur.
"There's the boy," said Uncle Wiggily, as he and the beaver chaps
reached the edge of the pond. "He's skating on thin ice. He'll go through
in a minute!"
And, surely enough, hardly had the bunny spoken than there was a
cracking sound, the ice broke beneath the boy's feet and into the dark,
cold water he fell.
"Oh! Oh!" cried the boy. "Help me, somebody! Oh! Oh!"
"Ha! It's a good thing Nurse Jane saw him!" said Uncle Wiggily. "Quick
now, Toodle and Noodle! I brought you along because you have such
good, sharp teeth—much sharper and better than mine are for gnawing
down trees. I can gnaw off the bark, but you can nibble all the way
through a tree and make it fall."
"Is that what you want us to do?" asked Toodle.
"Yes," answered Uncle Wiggily. "We'll go close to shore, where the boy
has fallen in. Near him is a tree. You'll gnaw that so it will fall outward
across the ice, and he can reach up, take hold of it and pull himself out
of the hole."
By this time the poor boy was floundering around in the cold water. He
tried to get hold of the edges of the ice around the hole through which
he had fallen, but the ice broke in his hands.
"Help! Help!" he cried.
"We're going to help you," answered Uncle Wiggily, but, of course, he
spoke animal language which the boy did not understand. But Toodle
and Noodle understood, and quickly running to the edge of the shore
they gnawed and gnawed and gnawed very extra fast at an overhanging
tree until it began to bend and break. Uncle Wiggily gnawed a little,
also, to help the beaver boys.
Then, just as the real boy was almost ready to sink down under water,
the tree fell on the ice, some of its branches close enough so the boy
skater could grasp them.
"Oh, now I can pull myself out!" he said. "This tree fell just in time! Now
I'll be saved!"
He did not know that Uncle Wiggily and the beaver boys had gnawed
the tree down, making it fall just in the right place at the right time. For
the boy was so frightened at having broken through the ice, that he
never noticed the bunny gentleman and the beaver boys on shore.
He caught hold of the tree branches in his cold fingers, pulled himself up
out of the water, that boy did; and to shore. Then as he sat down, all
wet and shivering, to take off his skates, so he could run home, Uncle
Wiggily called to Toodle and Noodle:
"Come on, beaver boys! Our work is done! We have saved that boy, and
I hope he never again tries to skate on thin ice."
Then Uncle Wiggily hopped toward his hollow stump bungalow, and the
beaver boys slid on the ice, near shore, toward their own stick-house,
for the pond was frozen hard and thick enough to hold them. And the
boy ran home as fast as he could, and drank hot lemonade so he
wouldn't catch cold.
He did get the snuffles, but of course that couldn't be helped, and it
wasn't much for falling through the ice; was it?
"You never should have gone skating until the pond was better frozen,"
his mother said.
"I know it," the boy answered. "But wasn't it lucky that tree fell when it
did?"
"Very lucky!" agreed his mother. And neither the boy nor his mother
knew that it was Nurse Jane, Uncle Wiggily and the beaver boys who
had caused the tree to topple over just in time.
But that's the way it sometimes is in this world. And if the cow doesn't
tickle the man in the moon with her horns, when she jumps over the
green cheese, I'll tell you next about Uncle Wiggily going coasting.
STORY XIV
UNCLE WIGGILY GOES COASTING
"Come on, Uncle Wiggily! Wake up! Wake up!" called Nurse Jane
Fuzzy Wuzzy in the hollow stump bungalow one morning. "Come on!"
"What's that? What's the matter? Is the chimney on fire again?"
asked the bunny gentleman, and he was so excited that he slid down
the banister, instead of hopping along from step to step as he should
have done.
"Of course the chimney isn't on fire!" laughed Miss Fuzzy Wuzzy. "But
this is the day for the picnic of the animal children, and you promised
to go with them to the woods."
"Oh, so I did!" exclaimed Uncle Wiggily, and he put one paw on his
pink nose to stop the twinkling, which started as soon as he grew
excited over thinking the chimney was on fire. "Well, I'm glad you
called me, Nurse Jane. I'll get ready for the picnic at once. What are
you going to put up for lunch?"
"Oh, some carrot bread, turnip cookies, lettuce sandwiches and nut
cake," answered the muskrat lady.
"That sounds fine!" laughed Uncle Wiggily. "I'm very glad I'm going
to the picnic!"
"Well, you had better hurry and get ready," remarked Miss Fuzzy
Wuzzy. "Here come Jackie and Peetie Bow Wow to see if you aren't
soon going to start."
Uncle Wiggily looked from the window of his hollow stump bungalow,
and saw the two little puppy dog boys coming along.
Jackie was so excited that he stubbed his paw and fell down twice,
while Peetie was so anxious to show Uncle Wiggily what was in the
package of lunch the puppies were going to take to the woods, that
Peetie fell down three times, and turned a back somersault.
"Uncle Wiggily! Uncle Wiggily! Aren't you coming?" barked Jackie.
"Hurry or it may rain and spoil the picnic," added Peetie.
"Oh, I hope not!" answered the bunny gentleman. "For if there is one
thing, more than another, that spoils a picnic, it is rain! Snow isn't so
bad, for we don't have picnics when it snows."
"Maybe it won't rain," hopefully spoke Nurse Jane, who was busy
putting up lunch for Uncle Wiggily. "There isn't a cloud in the sky!"
And, surely enough, when Uncle Wiggily, Nurse Jane and dozens of
animal children started off to the woods for their picnic, the sun
shone bravely down from the blue sky and a more lovely day could
not have been wished for.
The forest where the bunny gentleman, Nurse Jane and the animal
children went for their picnic was a large one, with many trees and
bushes. There were dozens of places for the squirrels, rabbits, goats,
ducks, dogs, pussy cats and others to play; and when they reached
the grove they put their lunches under bushes, on the soft cool,
green moss and began to have fun.
"Oh, Uncle Wiggily! Please turn skipping rope for us?" begged
Brighteyes, the little guinea pig girl.
"And please come play ball with us!" grunted Curly and Floppy
Twistytail, the piggie boys.
"Have a game of marbles with us," teased Billie Wagtail, the goat,
and Jacko Kinkytail, the monkey chap.
"I'll play with you all in turn," laughed the bunny gentleman. He was
in the midst of having fun, and was just gnawing off a piece of wild
grape vine to make a swing for Lulu and Alice Wibblewobble, the
ducks, when up came hopping Bully No-Tail, the frog boy. Bully was
quite excited.
"What's the matter, Bully?" asked Uncle Wiggily.
"Oh, gur-ump!" croaked Bully. "There is a big crowd of boys and girls
over on the other side of the pond. They're having a picnic, too! Ger-
ump! Ger-ump!"
"Real boys and girls!" added Bawly, who was Bully's brother. "Hump-
bump!"
"Well, that will do no harm!" laughed Uncle Wiggily. "Let the real boys
and girls have their picnic. They will not see us, for very few boys and
girls know how to use their eyes when they go to the woods. I have
often hidden beside a bush close to where a boy passed, and he
never saw me. Let the boys and girls have their picnic, and we'll have
ours!"
So that's the way it was. Uncle Wiggily and the animal children played
tag, and they slid down hill. Perhaps you think they could not do this
in summer when there was no snow. But the hills in the forest were
covered with long, smooth, brown pine needles, and these layers of
needles were so slippery that it was easy to slide on them.
And then, all of a sudden, just about when it was time to eat lunch, it
began to rain! Oh, how hard the drops pelted down! Rain! Rain! Rain!
"Scurry for shelter—all of you!" cried Nurse Jane. "Get out of the
rain!"
The animal boys and girls knew how to take care of themselves in a
rain storm, even if they had no umbrellas. Most of them had on fur or
feathers which water does not harm. And they snuggled down under
trees and bushes, finding shelter and dry spots so that, no matter
how hard it poured, they did not get very wet.
They hid their lunches under rocks and overhanging trees so nothing
was spoiled. And when the rain was over and the sun came out, as it
did, the animal picnic went on as before, and when the food was set
out on flat stumps for tables, there was enough for everyone, and
plenty left over.
Nurse Jane was looking at what remained of the good things to eat
when Jackie Bow Wow, who, with Peetie, had been splashing in a
mud puddle, came running up wagging his tail.
"Oh, Uncle Wiggily!" barked Jackie. "What you think? Those real
children, on the other side of the wood, they had their things to eat
out on some stumps for tables, just as we had, and when the rain
came, oh! it spoiled everything!"
"They didn't know how to keep their lunches dry," added Peetie.
"Now they haven't anything to eat for their picnic, and they are
starting home, and some of the little girls are crying."
"That's too bad!" murmured Uncle Wiggily, kindly. "Too bad that the
rain had to spoil their picnic! Now we have plenty of things left that
children could eat—nuts, apples, some popcorn and pears," for the
animal folk had brought all these, and many more, to the woods with
them. "We have lots left over."
"We could give them something to eat," spoke Nurse Jane, "but how
are we going to get it to them? We can't call them here; and it would
never do to let them see us carrying the things to them."
"No," agreed Uncle Wiggily. "But I think I have a plan. We can make
some baskets of birch bark. Some of the animal children—such as
Jacko and Jumpo Kinkytail, the monkeys, Joie and Tommie Kat,
Johnnie and Billie Bushytail, the squirrels—are good tree climbers. Let
them climb trees near where the real children are having their picnic,
and lower to them, on grape-vine ropes, the food we have left."
"Oh, yes!" mewed Tommie, the kitten boy. "What jolly fun!"
Quickly Nurse Jane began to gather up the food. Uncle Wiggily put it
in birch bark baskets the animal children made and then, with the
baskets, fastened to vines, in their paws or claws, the animal boys
went through the wood to the place of the other picnic. Uncle Wiggily
and the remaining animal children followed.
There the poor, disappointed real children were, looking at their rain-
soaked and spoiled lunches. Some of the little girls were crying.
"We might as well go home," grumbled a boy. "Our picnic is no
good!"
"Mean old rain!" sighed a girl.
But just then the animal chaps with lunch from Uncle Wiggily's picnic
—lunch which had not been rained on—climbed up into trees over the
heads of the boys and girls. Not a sound did the animal chaps make.
And when the real boys and girls had their backs turned, there were
lowered to the stump tables enough good things for a jolly feast—
apples, pears, popcorn, nuts and many other dainties.
A little girl happened to turn around and see the birch bark baskets of
good things just as the animal boys scurried off through the trees.
"Oh, look!" cried the girl. "The fairies have been here! They have left
us some lunch in place of ours that the rain spoiled. Oh, see the fairy
lunch!"
And I suppose that is as good a name for it as any, since the boys
and girls didn't see Uncle Wiggily's friends lower the baskets from the
trees. And the real boys and girls ate the lunch and had a most jolly
time, and so did the bunny gentleman and his picnic crowd.
Now if the rubber plant doesn't stretch over and tickle the teapot so
that it pours coffee instead of milk into the sugar bowl, you may next
hear about Uncle Wiggily in the rain storm.
STORY XVI
UNCLE WIGGILY'S RAIN STORM
That is the verse the little girl recited over and over again as she
watched the rain pelting down. But the storm did not stop for all that
she said the verse backward and frontward.
"Will it ever stop?" crossly cried the boy. "Why doesn't it stop?" and
he drummed on the window sill, banged his feet on the floor and
whistled. And his sister loudly recited over and over again:
"Rain, rain, go away!"
"Children! Children!" gently called Mother from where she was lying
down in the next room. "Can't you please be a little quiet? My head
aches and I am trying to rest. The noise makes my pain worse."
"We're sorry, Mother," said the girl.
"But being quiet isn't any fun!" grumbled the boy. "Why can't we go
out and play?"
"Because you would get all wet," answered his mother. "I've told you
that two or three times, dear. Now please be quiet. It will stop
raining sometime, and then you may go out."
"What can we play with?" asked the boy, not very politely I'm sorry
to say.
"Why, some of your toys," replied his mother. "Surely you have
enough."
"I'm tired of 'em!" grunted the boy.
"So'm I," echoed his sister.
Then she began once more to say the verse about the rain, as if that
would do any good, and the boy rubbed his nose up and down the
window, making queer marks.
Uncle Wiggily, on his way to see Grandpa Goosey Gander, and get a
watermelon for Nurse Jane, took a short cut through a field, and
passed the house where the children were kept in on account of the
rain. And, as it happened, the window near which the boy and girl
stood was open a little way at the top.
So, as the bunny gentleman hopped past, he not only saw the
children, but he heard what they said, being able, as I have before
related to you, to understand real talk.
But the children were looking up at the sky so intently, trying to see
if it would stop raining, that they never noticed Uncle Wiggily.
Though if they had seen him, all dressed as he was like a gentleman
from the moving pictures, they would have been very much
surprised.
"Too bad those children have to stay in on account of the rain,"
thought Uncle Wiggily. "I wonder if I couldn't find some way of
amusing them? If they are tired of their own playthings I might toss
in, through the open window, some of the things the animal boys
and girls play with. I'll do it!"
Off through the woods in the rain hopped Uncle Wiggily. He found a
number of smooth, brown acorns, some of which had the cups, or
caps still on. He filled one pocket with the acorns.
Next the bunny picked up some cones from the pine tree. There
were large and small cones, and Nurse Jane always used one as a
nutmeg grater, it was so rough, while Uncle Wiggily kept one near
his bed to scratch his back at night.
"Let me see, what else would the animal children take?" said the
bunny to himself. "I think they would take some green moss, and
the girls would make beds with it for their dolls. The animal boys
would take hollow reeds and blow little pebbles through them as real
boys blow beans in their tin shooters. I'll take some moss and
reeds."
This the bunny uncle did, also picking up some empty snail and
periwinkle shells he found on the bank of a brook.
"The little girl can string these shells for beads," thought the bunny.
"And I'll strip off some pieces of white birch bark so the boy can
make a little canoe, as the Indians used to do."
Having gathered all these things—playthings which the animal
children found in the woods every day—the bunny hopped back to
the house of the boy and girl. The window was open, but the boy
and girl had left it. The girl was giving her mother a drink of water,
and the boy was bringing up some coal for the fire.
"This is my chance!" thought Uncle Wiggily.
Standing outside, he tossed in through the open window the acorns,
the pine cones, the shells, the moss and other things. Then he
hopped quickly away and hid behind a bush. He could hear the
children come back into the room, and soon he heard the girl cry:
"Oh, look what the wind blew in! Some acorns! I can make little
cups of them, and use the tops for saucers! And I'll set a play-party
table for my doll, and decorate it with green moss. Oh, how perfectly
lovely!"
"I'm going to make a boat out of this birch bark!" cried the boy. "And
look! A hollow reed, like a bean blower! Now I can have some fun!"
"Look at the lovely shells I can string and make a necklace of!" went
on the girl.
"And I can make wooden legs, and a wooden head and stick em on
these pine cones and make believe they're Noah's ark animals!"
laughed the boy. "Hurray!" he cried most happily.
"What is going on out there?" called Mother from where she was
lying down. "Have you found something to play with?"
"Yes'm," answered the boy. "We'll be quiet now."
"And we don't care if it does rain," said the girl. "The wind blew a lot
of lovely things in the window!"
But of course we know that Uncle Wiggily tossed them in.
"I guess they'll be all right now, no matter how much it rains," said
the bunny, as he hopped along to see Grandpa Goosey, and buy the
snowmelon—excuse me, I mean the watermelon—for Nurse Jane.
So this teaches us that sometimes a rain storm is good for letting
you find out new ways of having fun. And if the looking-glass doesn't
make funny faces at the rag doll, when she's trying to see if her hair
ribbon is on backward, on the next page you may read about Uncle
Wiggily and the mumps.
Note
Uncle Wiggily specially requests that the following story will NOT be
read to children who have the mumps. Please wait until they are
better.
STORY XVII
UNCLE WIGGILY AND THE MUMPS
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.
ebookname.com