求指教啊
javascript吧
全部回复
仅看楼主
level 8
jy03692141 楼主
<script>
function func(name,sex,age)
{
this.name=name;
this.sex=sex;
this.age=age;
this.get=get;
}
function get()
{
return this.name;
}
var e=new func("的","男","18");
var b=e.get();
document.write(b);
</script>
代码如上。请问第7行这个this.get=get;到底是干什么用的呢?把这个删掉 代码就不执行了。
2012年03月19日 11点03分 1
level 5
觉得应该是this。get=get()吧。。。菜鸟 勿喷
2012年03月19日 12点03分 2
level 1
this.get的意思就是把function get(){ return this.name;} 这个函数作为function func(name,sex,age)的方法。 在javascript里 函数也就是一个对象。 你可以把func(name,sex,age)看成是一个对象,那么这个对象的属性就有name,sex等, 它的方法就是get()这个了
2012年03月20日 16点03分 3
level 8
new那一行,执行this.get=get时,在func里找不到get,向上找到get,相当于把声明的get赋到this.get,new的时候this指向e了
2012年03月20日 23点03分 4
1