作为一个好的脚手架使用

/*
Base.js, version 1.1a
Copyright 2006-2010, Dean Edwards
License: http://www.opensource.org/licenses/mit-license.php
*/ var Base = function() {
// dummy
}; Base.extend = function(_instance, _static) { // subclass
var extend = Base.prototype.extend; // build the prototype
Base._prototyping = true;
var proto = new this;
extend.call(proto, _instance);
proto.base = function() {
// call this method from any other method to invoke that method's ancestor
};
delete Base._prototyping; // create the wrapper for the constructor function
//var constructor = proto.constructor.valueOf(); //-dean
var constructor = proto.constructor;
var klass = proto.constructor = function() {
if (!Base._prototyping) {
if (this._constructing || this.constructor == klass) { // instantiation
this._constructing = true;
constructor.apply(this, arguments);
delete this._constructing;
} else if (arguments[0] != null) { // casting
return (arguments[0].extend || extend).call(arguments[0], proto);
}
}
}; // build the class interface
klass.ancestor = this;
klass.extend = this.extend;
klass.forEach = this.forEach;
klass.implement = this.implement;
klass.prototype = proto;
klass.toString = this.toString;
klass.valueOf = function(type) {
//return (type == "object") ? klass : constructor; //-dean
return (type == "object") ? klass : constructor.valueOf();
};
extend.call(klass, _static);
// class initialisation
if (typeof klass.init == "function") klass.init();
return klass;
}; Base.prototype = {
extend: function(source, value) {
if (arguments.length > 1) { // extending with a name/value pair
var ancestor = this[source];
if (ancestor && (typeof value == "function") && // overriding a method?
// the valueOf() comparison is to avoid circular references
(!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) &&
/\bbase\b/.test(value)) {
// get the underlying method
var method = value.valueOf();
// override
value = function() {
var previous = this.base || Base.prototype.base;
this.base = ancestor;
var returnValue = method.apply(this, arguments);
this.base = previous;
return returnValue;
};
// point to the underlying method
value.valueOf = function(type) {
return (type == "object") ? value : method;
};
value.toString = Base.toString;
}
this[source] = value;
} else if (source) { // extending with an object literal
var extend = Base.prototype.extend;
// if this object has a customised extend method then use it
if (!Base._prototyping && typeof this != "function") {
extend = this.extend || extend;
}
var proto = {toSource: null};
// do the "toString" and other methods manually
var hidden = ["constructor", "toString", "valueOf"];
// if we are prototyping then include the constructor
var i = Base._prototyping ? 0 : 1;
while (key = hidden[i++]) {
if (source[key] != proto[key]) {
extend.call(this, key, source[key]); }
}
// copy each of the source object's properties to this object
for (var key in source) {
if (!proto[key]) extend.call(this, key, source[key]);
}
}
return this;
}
}; // initialise
Base = Base.extend({
constructor: function() {
this.extend(arguments[0]);
}
}, {
ancestor: Object,
version: "1.1", forEach: function(object, block, context) {
for (var key in object) {
if (this.prototype[key] === undefined) {
block.call(context, object[key], key, object);
}
}
}, implement: function() {
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] == "function") {
// if it's a function, call it
arguments[i](this.prototype);
} else {
// add the interface using the extend method
this.prototype.extend(arguments[i]);
}
}
return this;
}, toString: function() {
return String(this.valueOf());
}
});

最新文章

  1. ALV中处理过滤掉的行
  2. 妈咪,我找到了! -- 15个实用的Linux find命令示例
  3. 搞懂Path环境变量
  4. PHP之运用CI用钩子实现URL权限控制————————【Badboy】
  5. WPF文本框只允许输入数字
  6. 用python来更改小伙伴的windows开机密码,不给10块不给开机
  7. springboot的拦截器Interceptor的性质
  8. Received empty response from Zabbix Agent at [172.16.1.7]...
  9. CentOS 修改用户密码
  10. hdu 5144 NPY and shot 物理+三分
  11. c++ 使用this指针进行串联的函数调用
  12. RHEL7 - 从命令行管理文件
  13. oracle基础之游标的理解与使用
  14. 部署weblogic 12c的几点收获
  15. SharePoint 2013 本地创建解决方案
  16. 【测试技术】websocket-client
  17. HTTP 方法:GET与 POST
  18. canvas入门(一)
  19. python 装饰器 回顾 及练习
  20. Java中Calendar/SimpleDateFormat/Date常用方法总结

热门文章

  1. 在使用Vue.js中使用axios库时,遇到415错误(不支持的媒体类型(Unsupported media type))
  2. 爬虫框架Scrapy之Request/Response
  3. [Network Architecture]ResNext论文笔记(转)
  4. PyTorch源码解读之torchvision.models(转)
  5. LA 3720 高速公路(互质判斜率)
  6. linux与window的\r与\n
  7. Mac OSX 如何在命令行中生成 md5、sha1、sha256 校验和
  8. 在.net中运用HTMLParser解析网页的原理和方法
  9. 转载:Javascript面向对象编程原理 -- 理解对象
  10. LeetCode 454. 4Sum II