The create
function from the underscore library is used to create a new object that inherits from a given prototype object. Here's how to use it:
index.tsx286 chars11 lines
In this example, we are creating a new childObject
that has parentObject
as its prototype. We are also adding a childProperty
to childObject
. When we log the childObject.parentProperty
, we are able to access parentObject
's property because childObject
is inheriting from it through the create
function.
Note that create
is a method of the underscore object, so you need to have the library loaded in your script before using it.
gistlibby LogSnag