作为一个好的脚手架使用

/*
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());
}
});

【javascript】base.js的更多相关文章

  1. 【JavaScript】关于JS中的constructor与prototype

    最初对js中 object.constructor 的认识: 在学习JS的面向对象过程中,一直对constructor与prototype感到很迷惑,看了一些博客与书籍,觉得自己弄明白了,现在记录如下 ...

  2. 【JavaScript】对JS的封装

    以下方法封装了获取ID元素的JS代码,调用以下代码方法并传值,则可以直接获取id所指元素 function $id(x) { //此处x只是形参,代表传进来的:要获取元素的id字符串 return d ...

  3. 【javascript】原生js更改css样式的两种方式

    下面我给大家介绍的是原生js更改CSS样式的两种方式: 1通过在javascript代码中的node.style.cssText="css表达式1:css表达式2:css表达式3  &quo ...

  4. 【JavaScript】初识js

    前端三大利器就是HTML+CSS+JavaScript,他们在整个前端开发中的主要作用大体可以概括如下 html 标记语言 负责页面的结构 css 层叠样式表 负责页面的样式 javascript 编 ...

  5. 【JavaScript】 knockout.js 日期格式化借助【momentjs】

    源:Knockout.js 日期格式化 源:momentjs

  6. 【JavaScript】用JS绘制一个球

    参考: 1.http://www.w3school.com.cn/html5/html_5_canvas.asp 2.http://blog.csdn.net/qq_27626333/article/ ...

  7. 【JavaScript】关于js的一些理解

    嵌套函数即作用域链:嵌套函数即闭包 函数表达式即延迟执行 匿名函数----------->实现块级作用域 call会切换到调用的对象参数环境.

  8. 【JavaScript】原生js实现:强制保留2位小数(由于toFixed()报错)

    function decimal(x) { var f = parseFloat(x); if (isNaN(f)) { alert("请输入数字!"); return; } va ...

  9. 【JavaScript】JS从入门到深入(复习查漏向

    [JavaScript]JS从入门到深入(复习查漏向 pre 精细得学过一遍JS后才发现,原来之前CTF中有些nodejs的题目以及一些游戏题的payload就变得很好理解了. 基础知识 ECMASc ...

随机推荐

  1. SQL Server-深入剖析统计信息

    转自: http://www.cnblogs.com/zhijianliutang/p/4190669.html   概念理解 关于SQL Server中的统计信息,在联机丛书中是这样解释的 查询优化 ...

  2. 无法读取服务器服务中的服务器队列性能数据。数据段的第一个四字节 (DWORD) 中包

    无法打开服务器服务性能对象.数据段的第一个四字节 (DWORD) 包含状态代码. 解决方法:修改注册表禁用PerfNet性能计数器. 具体方法:打开注册表,在HKEY_LOCAL_MACHINE\SY ...

  3. PyTorch源码解读之torch.utils.data.DataLoader(转)

    原文链接 https://blog.csdn.net/u014380165/article/details/79058479 写得特别好!最近正好在学习pytorch,学习一下! PyTorch中数据 ...

  4. ADO.NET 使用DELETE语句批量删除操作,提示超时,删除失败,几种优化解决思路

    起因是如此简单的一句sql 提示:Timeout 时间已到.在操作完成之前超时时间已过或服务器未响应. 提供几种解决思路: 1.检查WHERE条件中字段是否已建索引 2.检查是否被其他表引用,引用表外 ...

  5. redis_port.py

    !/usr/bin/env python import os import json import simplejson as json t=os.popen("""su ...

  6. 如何删除linux是用root生成的文件夹以及文件

    rm -rf 文件名 管理员的身份进行删除

  7. Struts2框架学习第一章——Struts2概述

    本章要点 —  Web应用的发展 —  Model 1和Model 2 —  MVC思想 —  MVC模式的优势 — 常用MVC框架及其特征 —  Struts 1的基本结构及其存在的问题 —  We ...

  8. SVN 与Eclipse 关联 || 安装beyond 插件

    1.让本地svn代码与库建立联系   右击项目名称,Team -  share project 2.本地svn版本一般与Eaclipse svn插件 版本一致!http://subclipse.tig ...

  9. 【三小时学会Kubernetes!(四) 】Deployment实践

    Deployment 部署 Kubernetes 部署可以帮助每一个应用程序的生命都保持相同的一点:那就是变化.此外,只有挂掉的应用程序才会一尘不变,否则,新的需求会源源不断地涌现,更多代码会被开发出 ...

  10. 如何选择正确的angular2学习曲线?

    参考: https://www.zhihu.com/question/50800464/answer/122921043 https://www.zhihu.com/question/48670501 ...