面向对象编程的好处就不说了,JavaScript也可以面向对象编程,如: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <script type="text/javascript"> var o={}; o.name='world'; o.eat=function(){ alert('function eat'); } var human=new Function(); human.prototype=o; var h=new human(); h.eat(); document.write(h.name); </script> </body> </html> 输出: 弹出 function eat world |
|
来自: 竹林书屋@ > 《JavaScript》