Top.Mail.Ru
? ?
Javascript's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Monday, January 3rd, 2005

Time Event
11:37a
value after redeclaring var
If I redeclare a possibly existing variable using var but no assignment, is it guaranteed to keep its old value if it had one? Example:
var mylang = 'fr';
// lots of HTML and script in between
var mylang;
if (mylang == 'fr')
  document.write('Bienvenu...');
else
  document.write('Welcome...');

The reason I need to know...Collapse )
11:35p
Define [] operator?
Is there a standard syntax for defining the [] operator for a given object? If so, what is it? Also, if the object already defines a [] operator, how may we preserve it so that we can call the old [] operator from our new [] operator?

For a project of a friend of mine, it would be convenient to redefine Array's [] operator to return Number.POSITIVE_INFINITY in the case that the value of a given index is undefined.

Alternatively, is there a standard way (or any way) of specifying a default value for "missing" elements in array literals. Ie, is there a way of specifying that executing v = [,1,,3] will leave v[0] == X and v[2] == X where X is some value of our choosing?

Thanks.

<< Previous Day 2005/01/03
[Calendar]
Next Day >>
About LiveJournal.com
Image