javascript Base类 包含基本的方法
作者:bea
代码如下: <script type="text/javascript"> function Base(){} //根抽象类 Base.toBase=function(){ //将一个对象转化成Base类的实例的方法 return new Base(); } Base.inherit=function(parent){ //用于继承Base类的实例的方法 var F=function(){} F.prototype=parent; retur
代码如下:
<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>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 运用jquery实现table单双行不同显示并能单行选中
- 用JQuery 实现AJAX加载XML并解析的脚本
- Prototype Selector对象学习
- Prototype 工具函数 学习
- 用js模仿word格式刷功能实现代码 [推荐]
- JQuery CSS样式控制 学习笔记
- JQuery 学习笔记 element属性控制
- JQuery 学习笔记 选择器之六
- JQuery 学习笔记 选择器之五
- JQuery 学习笔记 选择器之四
- JQuery 学习笔记 选择器之三
- JQuery 学习笔记 选择器之二
- JQuery 学习笔记 选择器之一
- javascript IFrame 强制刷新代码
- jQuery TextBox自动完成条
- JavaScript 动态生成方法的例子
- JavaScript 就地编辑HTML节点实现代码
- 模仿jQuery each函数的链式调用
- js 代码集(学习js的朋友可以看下)