Skip to content

deriveScope -> Scope<T>

function Fusion.deriveScope<Existing, AddMethods...>(
    existing: Scope<Existing>,
    ...: (AddMethods & {})...
): Scope<merge(Existing, AddMethods...)>

Returns a blank scope with the same methods as an existing scope, plus some optional additional methods which are merged in to only the new scope.

Unlike innerScope, the returned scope has a completely independent lifecycle from the original scope.

Pseudo type

Luau doesn't have adequate syntax to represent this function.

Scopes are not unique

Fusion can recycle old unused scopes. This helps make scopes more lightweight, but it also means they don't uniquely belong to any part of your program.

As a result, you shouldn't hold on to scopes after they've been cleaned up, and you shouldn't use them as unique identifiers anywhere.


Parameters

existing : Scope<T>

An existing scope, whose methods should be re-used for the new scope.

... : AddMethods...

A series of tables, ideally including functions which take a scope as their first parameter. Those functions will turn into methods on the scope.


Returns -> Scope<T>

A blank (non-inner) scope with the same methods as the existing scope, plus the extra methods provided.


Learn More

Back to top