Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

Javascript question about objects

$
0
0

Hi,

 

Let's say I've created a new object. One of the properties of my object

is an array. I would like another property to return the length of that

array. How do I do this.

 

For instance here's some code (and I hope that the email interface

doesn't screw this up so badly to make it unreadable. I'm going to avoid

using square brackets as well by using round ones instead even though

it's a syntax error, since square ones are known not to work with email.)

 

function test(){

     this.a = new Array();

     this.b = this.a.length;

}

 

x = new test();

x.a(0) = 3;

x.a(1) = 3;

x.b;

 

Returns 0. In other words, just setting this.b = this.a.length doesn't

not get updated automatically as this.a is added to.

 

Now, I tried turning this.b into a method (ie this.b = function(){return

this.a.length)  and that works, but then to get the length I keep having

to refer to myObject.b().

 

How can I avoid that? How can I have a built-in length property for an

object.

 

Hope this is clear and has come out legibly via email. Apologies in

advance if it hasn't.

 

Thanks,

Ariel

 


Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>