为什么一加这段就undefined呢?
就是模仿java里面的ArrayList。 为什么一加这段就undefined呢?
ArrayList.prototype.ensureCapacity = function(iCapacity) {
this.arr = new Array(iCapacity);
};
程序代码:
[code=HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www. <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Person</title> <script language="JavaScript"> function ArrayList() { this.arr = new Array(); this.iListSize = 0; ArrayList.prototype.ensureCapacity = function(iCapacity) { this.arr = new Array(iCapacity); }; ArrayList.prototype.add = function(item) { this.arr.push(item); this.iListSize++; }; ArrayList.prototype.get = function(index) { return this.arr[index]; }; ArrayList.prototype.size = function() { return this.iListSize; }; } var aL = new ArrayList(); aL.ensureCapacity(3); aL.add("A"); aL.add("B"); aL.add("C"); for (var i = 0; i < aL.size(); i++) { alert(aL.get(i)); } </script> </head> <body> </body> </html>