简单javaScript

ContractedBlock.gif ExpandedBlockStart.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

转载于:https://www.cnblogs.com/eping/archive/2009/09/15/1567191.html

你可能感兴趣的:(简单javaScript)