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

Calling methods


Objects don't just come with static property values—some of these values are callable functions. Functions assigned as an object's property are often referred to as methods, since they're generally interacting with the encapsulated state of the object to which they belong. Other times, objects are just a convenient vehicle for assigning and passing functions around the code. At the end of the day, they're just functions assigned to property values and Lo-Dash has some functions that assist with finding and calling them.

Getting results

We can use the result() function when we're unsure whether a given property name is a function or another type. This can simplify our code greatly because we don't need to write code that checks whether the property should be accessed like a regular static property value or if the property needs to be invoked. The usage of the result() function is shown in the following code:

var object1 = { 
        name: 'Brian'
    },  
    object2 = { 
  ...