J
John G Harris
<snip>VK said:List data type v.2
1) Correct term use (List not Vector): Ray, Harris
2) splice() to insert an element optimization: Ray
<html>
<head>
<title>List constructor</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>
function List(arr) {
this.$_$ = arr || new Array();
this.length = this.$_$.length;
this.add = List.$add;
this.remove = List.$remove;
this.toString = List.$toString;
}
Why don't you give List objects a prototype ?
P.S. what do $add, $remove and so names (starting with $)? Just a
marker of identifiers used only internally (that would be "private"
modifier if existed). Some are using underscores instead (_add,
_remove), but it is really an in-company choice, could be even prvtAdd,
prvtRemove. That is to make the track of vars easier and - if needed -
to have one click conversion to JScript.NET
length needs to be Read Only a lot more than the internal array needs to
be private. If someone changes a List object's length value then you're
scuppered. A length() method accessing the object's array would be a lot
safer.
John