google maps里最重要的对象应该算是GMapsApplication了,它的定义用到了javascript面向对象设计方法。
var a=z.prototype;
W("GMapsApplication",z);
P(z,"getMap",a.N);
function W(a,b){window[a]=b}
function P(a,b,c){a.prototype[b]=c}
z.prototype.N=function(){return this.a}
W函数把对象放在window属性里,可以为一个对象定义一个名称;
P函数则通过ptototype给对象增加方法别名。
有了这些,就可以用
var a = new GMapsApplication(e("map"));
像实例化一个javascript内置对象一样来实例化GMapsApplication了。
用起来还真方便。感觉把c#编程和脚本编程给拉近了一大截。
自己也写了个测试用例:
<script>
window["Hello"] = aa;
function aa()
{
this.x = 5;
this.y = 6;
this.test = function(a)
{
alert(a + "," + this.x + "," + this.y);
}
}
var xx = new Hello();
xx.test("bb");
</script>
window["Hello"] = aa;
function aa()
{
this.x = 5;
this.y = 6;
this.test = function(a)
{
alert(a + "," + this.x + "," + this.y);
}
}
var xx = new Hello();
xx.test("bb");
</script>