JAVASCRIPT 面向对象入门 示例

来源:互联网 发布:c语言大于符号怎么写 编辑:程序博客网 时间:2024/04/28 23:15
<html ><head><title></title></head><body>




<script type="text/javascript">/*person class*/function Person(name){this.name = name;}Person.prototype ={getName : function(){return this.name;},setName : function(name){this.name = name;},showName : function(){alert(this.name);}}var xm = new Person("xiaoming");xm.showName();xm.setName("zhangsan");xm.showName();/*extend class(dynamic)*/Person.prototype.getGreeting = function(){return "hello," + this.name;}alert(xm.getGreeting());/**/</script>


</body></html>


原创粉丝点击