ITeye博客

类的实例的问题

katelin · 2007-09-12 09:55 · Web前端 · Markdown

下面的代码,alert出来的结果,说明这个时候t是return的那个html对象,而非Test的实例。为啥啊?我知道一般写成类的形式是不带return的。


<input type="text" name="myText">
<script language="JavaScript">
<!--
	function Test(id){
		this.type = 'class test';
		return document.getElementById(id);
	}

	var t = new Test('myText');
	alert(t.type); //结果是text,看来这时候t是myText这个html对象而非Test类的实例
//-->
</script>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。