JavaScript Object References

Objects are always referenced in JavaScript. When you put such a reference as the right value of an assignment expression, what is assigned to the left value element is this reference. An object is never referenced another way in this programming language.

Let us see a simple example with empty object literals being assigned to multiple variables:

var a = {}, b = {}, c = {};

Each variable has a reference to a distinct empty object.

Now:

a = b = c = {};

All three variables have the same reference, to the same empty object.

Simple enough.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">