模仿mootools对象创建方法 简单的实现
2012-03-28 10:57
549 查看
var extend = function(destination, source, override) { if (override === undefined) override = true; for (var property in source) { if (!override && typeof(source[property]) == 'function' && destination.hasOwnProperty(property)) { destination[property] = (function(name, method) { return function() { this.base = source[name]; return method.apply(this, arguments); } })(property, destination[property]); } else { destination[property] = source[property]; } } return destination; }; var Class = function(implements) { if (typeof implements == 'undefined') return; var newClass = function() { extend(this, implements); this.initialize.apply(this, arguments); }; newClass.prototype.setOptions = function(opts) { extend(this.options, opts || {}); return this; }; return newClass; }; var Tab = new Class({ options : { name : 'test' }, initialize : function(opts) { this.setOptions(opts); alert(this.options.name); }, show : function() { return 'i will show'; } }); var t = new Tab({ name : 'newName' }); alert(t.show());
欢迎大家给改进意见!
相关文章推荐
- 细说jQuery原型的创建和实现原理,并用实例简单模仿
- 自己实现简单的AOP(二)引入Attribute 为方法指定增强对象
- 简单属性,方法,对象的创建和使用
- Python字典数据对象拆分的简单实现方法
- 类方法 (不用创建对象直接用对象实现)
- json对象与数组以及转换成js对象的简单实现方法
- javascript创建对象,以及实现继承的方法
- php模仿asp Application对象在线人数统计实现方法
- php模仿asp Application对象在线人数统计实现方法
- javascript实现创建对象的三种方法
- 使用hadoop命令rcc生成Record 一个简单的方法来实现自己的定义writable对象
- OC学习笔记01-类的声明实现与对象创建,方法声明实现与调用及传参
- 创建ajax对象并兼容多个浏览器方法简单记录
- Spring创建对象工厂功能的简单实现
- Servlet的简单实现和核心类对象 方法
- JAVA中创建线程对象的两种方法:继承Thread和实现Runable
- 设计模式:对象创建(原型,单例,简单工厂,工厂方法,抽象工厂,生成器)
- C# 反射-通过继承接口实现创建对象并调用方法
- 用C语言模仿Python函数的一种简单实现方法
- SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序