Print the handler / link of an array (or object) in Javascript

Possible duplicate:
How to get the memory address of a JavaScript variable?

Is there a way in javascript to print an array reference?

What I want to do is to check if the two arrays have the same link, and this can be done as shown in this post: How to check if the two arrays have the same link?

But is it possible to print the link if, for example, I work with an array?

Example

var Array1=["hi"]; var Array2=["hello"]; var thesame = Array1==Array2; 

same false value.

But can I print a link to Array1 with something like window.alert(@Array1); in javascript?

- UPDATE -

What I definitely want is the actual address space referenced.

+7
source share
2 answers

Javascript implementations are standardized only to the extent that they comply with the ECMA specification. The details of data storage may vary by browser and are not available for JS.

Regarding your question about why: JS is a lightweight scripting language. It makes sense to delegate memory management and optimization tasks to the platform, while this will require unnecessary switching to bypass to provide you with an interface for this.

+3
source

If you want to see the value of some pointer to a reference type (array, object), you cannot.

For example, in Perl, you have a scalar type that is a reference to something. When you print this scalar, you can get something like a string representation of a pointer to a value. There is no analogy to this kind of scalar in JavaScript.

You can only check if two links point to the same thing or not.

As in all languages ​​with GC, in JavaScript you cannot be sure that the same object will have the same memory pointer along the execution of the program (you can move it to the heap). As I mentioned, you do not have a pointer abstraction as a type of embedded language. Therefore, showing the current link may not be a good idea, because it can be dynamic (depending on the engine architecture and especially the GC).

+4
source

All Articles