cloudflare / cloudflare/cloudflare-docs

Rules of Durable Objects out-of-date init() method description

Open
#30,707 1 comment 0 reactions 6 assignees Claimed by @vy-ton View on GitHub
content:edit documentation product:durable-objects stale
Dominant language
MDX
Stars
5.2k
Forks
16.7k
Avg merge
2d 6h
Merged PRs (30d)
337

Description

### Existing documentation URL(s)

https://developers.cloudflare.com/durable-objects/best-practices/rules-of-durable-objects/#initialize-durable-objects-explicitly-with-an-init-method

### What changes are you suggesting?

This is out of date:
> ### Initialize Durable Objects explicitly with an init() method
> Durable Objects do not know their own name or ID from within. If your Durable Object needs to know its identity (for example, to store a reference to itself or to communicate with related objects), you must explicitly initialize it.

The `ctx: DurableObjectState` property of the `DurableObject` (and constructor parameter) provides the `id`, and (where relevant) `name`. An explicit `init` method is no longer required to know its own identity, but may still be useful for other application-defined identifiers.

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.