<code>
var
arrServerPoint =
new
Array([
new
ServerPoint()]);
var
sp = arrServerPoint[0];
var
sp2 =
new
ServerPoint();
console.log(sp);
[ServerPoint]
0: ServerPoint
length: 1
__proto__: Array[0]
console.log(sp2);
ServerPoint {sPoint: H, sRadius: 1000, marker: R, circle: zc, constructor:
function
…}
...
__proto__: ServerPoint
发现先返回的对象原型不一样,所以想通过arrServerPoint[0]的方式调用ServerPoint类内的方法,返回错误;
是否我使用数组的方式不对?
请大大们帮忙!
*----上面问题已解决,是我粗心和基础不扎实。----
----应为:
var
arrServerPoint =
new
Array(
new
ServerPoint());----
----不过有又新的问题。发现修正上面问题后。通过第一种方式获取的对象类型,还是无法访问到其内部方法----
----ServerPoint类的构造函数如下----*
function
ServerPoint(sPoint, sRadius) {
this.sPoint = sPoint;
this.sRadius = sRadius;
}
ServerPoint.prototype = {
constructor: ServerPoint,
setPoint:
function
(setPoint) {
this.sPoint = setPoint;
},
getPoint:
function
() {
return
this.sPoint;
},
setRadius:
function
(setRadius) {
this.sRadius = setRadius;
},
getRadius:
function
() {
return
this.sRadius;
},
}
var
arrServerPoint =
new
Array(
new
ServerPoint());
var
sp = arrServerPoint[0];
var
sp2 =
new
ServerPoint();
</code>