![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
//alert(typeof(null)); object 类型
function University(name,city)
{
this.name = name;
this.city = city;
//这里添加toString方法
this.toString = universityToString;//函数后面没有加圆括号,这不是一个函数调用,而是对函数自身的引用
alert(this.toString());
}
function universityToString()
{
return this.name +"is in "
+this.city;
}
</script>
<body >
<form id="myForm">
<input type="button" value="test" onclick=University('"华东交通大学"',"南昌")>
</input>
</form>
</body>
</html
posted @
2009-09-15 17:45
eping
阅读(
184)
评论()
编辑
收藏
举报