面向对象编程的好处就不说了,JavaScript也可以面向对象编程,如:
<!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>
</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
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。