日期:2014-05-16 浏览次数:20325 次
var Time = { today: ‘2009-3-8′, weather: ‘rain’, show: function(){ alert(‘Today is ‘ + this.today); } };
function time() { var today = '2009-3-8', weather = 'rain'; this.show = function () { alert('Today is ' + today); } }
------解决方案--------------------
你说的是js中如何使用类?如果是的话你可以参考一下这个帖子:
js中的类
------解决方案--------------------
<!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'; return { show: function() { alert('Today is ' + today); } }; })(); Time.show(); </script> </head> <body> </body> </html>