<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> var Time = (function() { var today = '2010-3-8'; var weather = 'rain';
var Time = {
today:'2009-3-8',
weather:'rain',
show: function(){
alert('Today is' + this.today);
}
};
var Time1={
today:'2010-3-8',
weather:'rain',
show:function(){
alert('Today is' + this.today);
}
};
Time.show();
Time1.show();PS:很弄不清楚你的题意……
function time() {
var today = '2009-3-8', weather = 'rain';
this.show = function () { alert('Today is ' + today); }
}
js中的类
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
var Time = (function() {
var today = '2010-3-8';
var weather = 'rain';
return {
show: function() {
alert('Today is ' + today);
}
};
})();Time.show();</script>
</head>
<body></body>
</html>