源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

javascript Base类 包含基本的方法

  • 时间:2020-03-29 10:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript Base类 包含基本的方法
[u]复制代码[/u] 代码如下:
<script type="text/javascript"> function Base(){} //根抽象类 Base.toBase=function(){ //将一个对象转化成Base类的实例的方法 return new Base(); } Base.inherit=function(parent){ //用于继承Base类的实例的方法 var F=function(){} F.prototype=parent; return new F; } Base.prototype.extend = function(prop){ //扩展根抽象类Base的extend方法 for (var o in prop) { this[o] = prop[o]; } } Base.prototype.method = function(name, fn){ //扩展根抽象类Base的method方法 this[name] = fn; return this; } var o=new Base(); //创建一个Base实例 o.method("show",function(){ //给对象o添加show方法 alert("show function"); }); o.extend({ //在给对象o添加name属性和say函数 name:"shupersha", say:function(){ alert("say function") } }); var t=Base.inherit(o); //继承o对象的属性和方法 t.show(); t.say(); </script>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部