js中prototype的一个小例子

来源:互联网 发布:underscore.js源码分析 编辑:程序博客网 时间:2024/04/20 23:18
<script type="text/javascript">function SUOLONG(title,content){  this.title=title||"tt";  this.content=content||"cc";  return this.title+this.content;}//给方法SUOLONG(title,content)再追加一个方法SUOLONG.prototype.sayhi= function(word){  this.hello=this.title+"--"+this.content+"--"+word;  return this.hello;}var v=new SUOLONG('t1','c1');alert(v.sayhi('kkk'));//t1--c1--kkk//var v2=SUOLONG('t2','c2');//这种写法错误//alert(v2.sayhi('kkk222'));//对象不支持此属性和方法</script>

原创粉丝点击