Book Image

Lo-Dash Essentials

By : Adam Boduch
Book Image

Lo-Dash Essentials

By: Adam Boduch

Overview of this book

Table of Contents (15 chapters)
Lo-Dash Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating and cloning objects


Our last topic of the chapter is that of creating and cloning JavaScript objects. We can get by on a day-to-day basis without putting too much thought into creating or cloning objects. The new keyword or the object literal notation serves us just fine. Rarely is there a need to clone objects. However, Lo-Dash nonetheless has tools to deal with both of these scenarios when the need arises.

Creating objects

The create() function helps us close the gap between functional and object-oriented paradigms. It allows us to leverage some crucial functional JavaScript components in our objects. Particularly, when it comes to specifying prototypes when creating new objects.

This might not sound like a big deal, but it can make for some fun, elaborate hacking. Let's say that we have a collection of objects defined using the literal notation. These objects have just straightforward string property values. Let's also say that we have a class that defines some behavior through...