---
name: "up.Layer.prototype.asCurrent"
area: "API"
kind: "Instance method"
parent: "up.Layer class"
url: "https://unpoly.com/api/up.Layer.prototype.asCurrent"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.Layer class](https://unpoly.com/api/up.Layer.md)</nav>

# up.Layer.prototype.asCurrent(fn)

Temporarily changes the [current layer](https://unpoly.com/api/up.layer.current.md) while the given function is running.

Calls the given function and restores the original current layer when the function terminates.

## Example {#example}

```js
up.layer.current // returns up.Layer.Root

up.layer.open() // open an overlay
up.layer.current // returns up.Layer.Modal

up.layer.parent.asCurrent(function() {
  up.layer.current // returns up.Layer.Root
})

up.layer.current // returns up.Layer.Modal
```

---

## Parameters {#parameters}

### fn {#fn}

(required)

The synchronous function to call.

Async functions are not supported.

Type: Function()

