# How to reuse a function

**URL:** <https://community.postman.com/t/how-to-reuse-a-function/39077>\
**Category:** Help Hub\
**Tags:** scripts, dry\
**Created:** [September 13, 2022, 10:25am UTC](https://community.postman.com/t/how-to-reuse-a-function/39077 "2022-09-13T10:25:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![atchyutpulavarthi](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/atchyutpulavarthi/32/28229_2.png) [@atchyutpulavarthi](https://community.postman.com/u/atchyutpulavarthi)\
**Post date:** [September 17, 2022, 2:27pm UTC](https://community.postman.com/t/how-to-reuse-a-function/39077/2 "2022-09-17T14:27:07Z")

</div>

@idpbee you could do the following:

- In the Collection level pre-request script, declare an object without using the `var`, `let` or `const` keywords. The object is then attached to the global sandbox and is available in child context of that collection.

**In the collection pre-request script:**

```auto
utils = {
    getEnv(v) {
        return pm.environment.get(v);
    }
}

```

**Now within any of the children of that collection, you could simply do the following:**

```auto
utils.getEnv('name');

```

---

_[View the full topic](https://community.postman.com/t/how-to-reuse-a-function/39077)._
