Table Of Contents

Previous topic

21.36. The Profile Object

Next topic

21.38. The Renderable Interface

This Page

21.37. The Reference Object

This provides a proxy object that can be used to implement weak referencing. One use case is the object managers that want to clear a dictionary entry when no other references exist.

Required scripts

The Reference object requires:

/*{{ javascript("jslib/utilities.js") }}*/

21.37.1. Constructor

21.37.1.1. create

Summary

Creates and returns a Reference object.

Syntax

var reference = Reference.create(objectToReference);
objectToReference
The object that should be reference counted.

21.37.2. Methods

21.37.2.1. add

Summary

Increment the reference count.

Syntax

reference.add();

21.37.2.2. remove

Summary

Decrement the reference count. When it reaches 0 the subscribed observer functions are called and the object.destroy() method is called.

Syntax

reference.remove();

21.37.2.3. subscribeDestroyed

Summary

Register a function to call when the reference count is 0.

Syntax

someObject.reference.subscribeDestroyed(onSomeObjectDestroyed);
onSomeObjectDestroyed
The function to call.

21.37.2.4. unsubscribeDestroyed

Summary

Unregister a previously subscribed function.

Syntax

someObject.reference.unsubscribeDestroyed(onSomeObjectDestroyed);
onSomeObjectDestroyed
The function previously passed to subscribeDestroyed().