- 浏览: 450083 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (158)
- J2SE (15)
- c/c++ (17)
- linux & ubuntu (20)
- js (18)
- algorithm (21)
- android (1)
- software (3)
- svn (1)
- db (6)
- other (19)
- css (5)
- go (1)
- html 5 (3)
- computer science (1)
- php (3)
- 创业 (8)
- EJB & jboss (1)
- TDD (1)
- jsp & servlet (2)
- http, tcp & ip (2)
- hibernate (1)
- json (1)
- 乐 (2)
- ps (2)
- netbeans (1)
- extjs (2)
- eclipse (4)
- 项目管理 (1)
- varnish (2)
- study abroad (1)
- python (1)
- erlang (1)
- math (1)
- shell (1)
- assembly (4)
- lucene (1)
- web (1)
- http (1)
- tcp & ip (1)
最新评论
-
yiguxianyun:
...
css li 不换行 -
stdayong:
...
netbeans 中使用 maven -
程序猿_星:
为啥会中文乱码啊
servlet 以 gzip 格式返回数据 -
huanhuan519:
感谢分享~
gdb 调试工具 -
heyl1234:
写过些js,对css还不熟。谢谢~
css li 不换行
define subclass - js
------
define subclass
definition of subclass:
assume there are function A and B, if A.prototype.prototype = B.prototype, then A is subclass of B,
to complete the subclass, there are more things to do than extends prototype, see following steps,
steps to create subclass:
* B.prototype extends from A.prototype
* B.prototype.constructor = B
* in B's constructor body
* use apply()/call() to invoke B's constructor with arguments,
* define new things for B,
* override A's method/property, if necessary,
* define things on new constructor
------
how create a prototype extends from another prototype
how to create sub prototype:
create a new function whose prototype is the super prototype, then the new function could be used as the sub prototype,
how to do:
* in ECMAScript5:
use Object.create(p),
* in ECMAScript3:
create an function, point its prototype to ther super prototype,
util function to create a sub prototype:
/** * create a sub prototype which extends from specified super prototype * * @param: p super prototype * @return sub prototype */ function inherit(p) { if (p == null) throw TypeError(); // p must be a non-null object if (Object.create) // If Object.create() is defined... return Object.create(p); // then just use it. var t = typeof p; // Otherwise do some more type checking if (t !== "object" && t !== "function") throw TypeError(); function f() {}; // Define a dummy constructor function. f.prototype = p; // Set its prototype property to p. return new f(); // Use f() to create an "heir" of p. }
------
abstract class / interface
abstract class & interface:
are class that include abstract method, in js abstract method could be a method that throw an exception,
implementation:
in the subclass, override the abstract method, thus get a class without abstract method,
------
e.g.
include:
* inherit_util.js
include some util methods for inherit,
* subclass_example_1.js
a example use inherit()/extend() directly,
* subclass_example_2.js
a example use defineSubclass(),
* subclass_example_3.js
a example use Function.prototype.extend(),
inherit_util.js:
/** * util function copy enumerable property of p to object o * * @param o * @param p * @returns */ function extend(o, p) { for (prop in p) { // For all props in p. o[prop] = p[prop]; // Add the property to o. } return o; } /** * create a prototype which inherit from specified prototype * * @param p * super prototype * @returns sub prototype */ function inherit(p) { if (p == null) throw TypeError(); // p must be a non-null object if (Object.create) // If Object.create() is defined... return Object.create(p); // then just use it. var t = typeof p; // Otherwise do some more type checking if (t !== "object" && t !== "function") throw TypeError(); // Define a dummy constructor function. function f() { } f.prototype = p; // Set its prototype property to p. return new f(); // Use f() to create an "heir" of p. } /** * util function to define subclass, extends from specified superclass, and add * new methods/properties to prototype/constructor, this function depends on * extend() & inherit(), * * @param superclass * Constructor of the superclass * @param constructor * The constructor for the new subclass * @param methods * Instance methods to copied to prototype, the param should be an * object contain methods/properties * @param statics * Class properties to copied to constructor, the param should be a * object contain methods/properties, * @return the new constructor */ function defineSubclass(superclass, constructor, methods, statics) { // inherit from super prototype constructor.prototype = inherit(superclass.prototype); // set the constructor property of the new prototype constructor.prototype.constructor = constructor; // copy instance properties/methods to copied to prototype if (methods) extend(constructor.prototype, methods); // copy class properties/methods to constructor if (statics) extend(constructor, statics); // Return the class return constructor; } /** * add the extend method to js Function, so that apply to all function of js, * * @param constructor * @param methods * @param statics * @returns the new constructor */ Function.prototype.extend = function(constructor, methods, statics) { return defineSubclass(this, constructor, methods, statics); }; /** * an abstract method, which throws error */ function abstractMethod() { throw new Error("method not implemented"); }
subclass_example_1.js:
// depends on inherit_util.js // super class function A() { this.pone = "A-pone"; this.ptwo = "A-ptwo"; } A.prototype.mone = function() { console.log("A-mone"); }; // super class has a abstract method A.prototype.mtwo = abstractMethod; A.prototype.mthree = function() { console.log("A-mthree"); }; // sub class function B() { // invoke super constructor on sub object, so that to extends things defined // in super constructor, A.apply(this); // override super property from super constructor, this.pone = "B-pone"; } // extends from super prototype B.prototype = inherit(A.prototype); // set the constructor property of sub prototype, after extends prototype, B.prototype.constructor = B; // implemet(override) abstract method of super class B.prototype.mtwo = function() { console.log("B-mtwo"); }; // override method of super class B.prototype.mthree = function() { console.log("B-mthree"); }; function test() { var b = new B(); b.mone(); b.mtwo(); b.mthree(); console.log(b.pone); console.log(b.ptwo); } test();
subclass_example_2.js:
// depends on inherit_util.js // super class function A() { this.pone = "A-pone"; this.ptwo = "A-ptwo"; } A.prototype.mone = function() { console.log("A-mone"); }; // super class has a abstract method A.prototype.mtwo = abstractMethod; A.prototype.mthree = function() { console.log("A-mthree"); }; // sub class function B() { // invoke super constructor on sub object, so that to extends things defined // in super constructor, A.apply(this); // override super property from super constructor, this.pone = "B-pone"; } // extends from super prototype defineSubclass(A, B, { mtwo : function() { console.log("B-mtwo"); }, mfour : function() { console.log("B-mfour"); } }, { sfone : "staticFieldOne" }); function test() { var b = new B(); b.mone(); b.mtwo(); b.mthree(); b.mfour(); console.log(b.pone); console.log(b.ptwo); console.log(b.constructor.sfone); } test();
subclass_example_3.js:
// depends on inherit_util.js // super class function A() { this.pone = "A-pone"; this.ptwo = "A-ptwo"; } A.prototype.mone = function() { console.log("A-mone"); }; // super class has a abstract method A.prototype.mtwo = abstractMethod; A.prototype.mthree = function() { console.log("A-mthree"); }; // sub class function B() { // invoke super constructor on sub object, so that to extends things defined // in super constructor, A.apply(this); // override super property from super constructor, this.pone = "B-pone"; } // extends from super class A.extend(B, { mtwo : function() { console.log("B-mtwo"); }, mfour : function() { console.log("B-mfour"); } }, { sfone : "staticFieldOne" }); function test() { var b = new B(); b.mone(); b.mtwo(); b.mthree(); b.mfour(); console.log(b.pone); console.log(b.ptwo); console.log(b.constructor.sfone); } test();
------
发表评论
-
link archor
2012-04-02 21:26 1368link archor http://www.x ... -
js closure
2012-03-02 18:21 1092js closure scope: in j ... -
js array methods
2012-03-02 15:14 2513js array method array ha ... -
js logic operator
2012-01-16 21:41 936logical expression of js ... -
js 检验 Array
2011-01-01 20:13 882检验是否是 Array 工具方法: function ... -
heap sort
2010-12-18 19:09 1236heapsort ------ heap 数据结构 hea ... -
js 图片延迟加载
2010-11-20 17:04 1626图片延迟加载 ------ 需求场景: 对于长页面,如果有 ... -
js 的 null & undefined 判断
2010-10-25 23:35 2232判断 null 或 undefined ------ 判断规 ... -
chrome 开发人员工具
2010-10-08 15:33 1700chrome 有自己的开发人员工具,类似 firefox 的 ... -
apply() & call()
2010-09-24 19:24 1094apply & call Function 对象 调 ... -
ascii & char & string of js
2010-09-11 19:02 3425ascii & char & string ... -
js String trim()
2010-09-10 00:06 17701为 js 添加 trim() 功能 js 默认不支持 tri ... -
js 实现 本地图片 预览
2010-08-26 10:59 3446js 实现 本地图片 预览 <!DOCTYPE H ... -
bassistance 's jquery plugin
2010-04-27 13:20 1274该网址下有些比较好用的 jquery plugin http ... -
andrew-hoyer webside
2010-03-05 17:18 897andrew-hoyer 's webside is fun, ... -
raphael js lib
2010-03-05 11:03 2652raphael js 是超级炫的 js 库,提供对 web 矢 ... -
js 倒计时
2010-03-03 18:00 3905写了个超简单的 js 倒计时,使用了 jquery1.4.2 ...
相关推荐
script src =" path/to/subclass.js " > </ script > < script src =" path/to/define-class.js " > </ script > < script > $ . defineClass ( 'my-class' , function ( pt ) { 'use ...
在Ext中,类实例属性可以通过类定义的配置项或者构造函数来设置,如`Ext.define('Person', {name: 'John'}`或`new Person({name: 'John'})`。 3. **类实例方法**:这些方法属于类的实例,每个实例都可以有自己的...
计算机硬件控制_驱动级键盘鼠标同步_PS2接口UDP协议多机协同_基于rabirdwinio和pynput的跨设备输入共享系统_实现多台Windows电脑的键盘鼠标同步操作_支持
嵌入式八股文面试题库资料知识宝典-TCPIP协议栈.zip
少儿编程scratch项目源代码文件案例素材-开膛手杰克.zip
基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现遥感图像滑坡识别源码+数据集+训练好的模型基于深度学习CNN网络+pytorch框架实现
内容概要:本文详细探讨了电力弹簧技术在主动配电网规划及运行优化调度中的应用。首先介绍了电力弹簧技术作为智能电网调控手段的优势,如自适应性强、响应速度快、节能环保等。接着阐述了主动配电网规划的目标和策略,包括优化电网结构、提高能源利用效率和降低故障风险。随后讨论了运行优化调度的原则和方法,强调了实时监测、智能调度策略以及优化调度模型的重要性。最后通过实际案例分析展示了电力弹簧技术在提升电网稳定性、可靠性和能效方面的显著效果,展望了其广阔的应用前景。 适合人群:从事电力系统规划、运行管理的研究人员和技术人员,以及对智能电网感兴趣的学者和学生。 使用场景及目标:适用于希望深入了解电力弹簧技术及其在主动配电网规划和运行优化调度中具体应用的专业人士。目标是掌握电力弹簧技术的工作原理、优势及其在实际项目中的实施方法。 其他说明:本文不仅提供了理论分析,还有具体的案例支持,有助于读者全面理解电力弹簧技术的实际应用价值。
嵌入式八股文面试题库资料知识宝典-C语言思维导图.zip
电路教学与科研案例的结合—以最大功率传输定理为例.pdf
内容概要:本文深入介绍了HarmonyOS文件系统及其在万物互联时代的重要性。HarmonyOS自2019年发布以来,逐步覆盖多种智能设备,构建了庞大的鸿蒙生态。文件系统作为其中的“数字管家”,不仅管理存储资源,还实现多设备间的数据协同。文章详细介绍了常见的文件系统类型,如FAT、NTFS、UFS、EXT3和ReiserFS,各自特点和适用场景。特别强调了HarmonyOS的分布式文件系统(hmdfs),它通过分布式软总线技术,打破了设备界限,实现了跨设备文件的无缝访问。此外,文章对比了HarmonyOS与Android、iOS文件系统的差异,突出了其在架构、跨设备能力和安全性方面的优势。最后,从开发者视角讲解了开发工具、关键API及注意事项,并展望了未来的技术发展趋势和对鸿蒙生态的影响。 适合人群:对操作系统底层技术感兴趣的开发者和技术爱好者,尤其是关注物联网和多设备协同的用户。 使用场景及目标:①理解HarmonyOS文件系统的工作原理及其在多设备协同中的作用;②掌握不同文件系统的特性和应用场景;③学习如何利用HarmonyOS文件系统进行应用开发,提升跨设备协同和数据安全。 阅读建议:本文内容详实,涵盖了从基础概念到高级开发技巧的多个层次,建议读者结合自身需求,重点关注感兴趣的部分,并通过实践加深理解。特别是开发者可参考提供的API示例和开发技巧,尝试构建基于HarmonyOS的应用。
嵌入式八股文面试题库资料知识宝典-海康嵌入式笔试题.zip
内容概要:本文详细介绍了基于瞬时无功功率理论的三电平有源电力滤波器(APF)仿真研究。主要内容涵盖并联型APF的工作原理、三相三电平NPC结构、谐波检测方法(ipiq)、双闭环控制策略(电压外环+电流内环PI控制)以及SVPWM矢量调制技术。仿真结果显示,在APF投入前后,电网电流THD从21.9%降至3.77%,显著提高了电能质量。 适用人群:从事电力系统研究、电力电子技术开发的专业人士,尤其是对有源电力滤波器及其仿真感兴趣的工程师和技术人员。 使用场景及目标:适用于需要解决电力系统中谐波污染和无功补偿问题的研究项目。目标是通过仿真验证APF的有效性和可行性,优化电力系统的电能质量。 其他说明:文中提到的仿真模型涉及多个关键模块,如三相交流电压模块、非线性负载、信号采集模块、LC滤波器模块等,这些模块的设计和协同工作对于实现良好的谐波抑制和无功补偿至关重要。
基于环比增长的销售统计分析——2019年中青杯全国数学建模竞赛C题.pdf
嵌入式八股文面试题库资料知识宝典-linux面试题.zip
嵌入式八股文面试题库资料知识宝典-linux常见面试题.zip
内容概要:本文探讨了小电流接地系统在配电网络中的应用,特别是在单相故障情况下的仿真分析。文中介绍了小电流接地系统的背景和发展现状,重点讨论了两种常见的接地方式——中性点不接地和中性点经消弧线圈接地。利用Matlab作为仿真工具,作者构建了详细的电路模型,模拟了单相故障的发生过程,并通过多个结果图表展示了故障电流、电压波形及系统运行状态。此外,文章还包括了详细的设计说明书和PPT介绍,帮助读者全面理解仿真过程和技术细节。 适合人群:从事电力系统研究、维护的技术人员,尤其是关注配电网络安全和稳定的工程师。 使用场景及目标:适用于希望深入了解小电流接地系统的工作原理和故障处理机制的专业人士。通过本研究,读者可以掌握如何使用Matlab进行电力系统仿真,评估不同接地方式的效果,优化配电网络的安全性能。 其他说明:随文附带完整的仿真工程文件、结果图、设计说明书及PPT介绍,便于读者进一步探索和实践。
少儿编程scratch项目源代码文件案例素材-激烈的殴斗.zip
嵌入式八股文面试题库资料知识宝典-小米嵌入式软件工程师笔试题目解析.zip
内容概要:本文详细探讨了车辆主动避撞技术中的两种常见策略——纵向紧急制动避撞和横向紧急转向避撞。首先介绍了这两种避撞策略的基本概念,接着深入分析了临界纵向安全距离的概念及其对避撞模式选择的影响。文中特别强调了五次多项式换道轨迹模型在计算横向紧急转向避撞安全距离中的应用。最后,通过一个简化的程序实现了避撞策略的模拟和可视化展示,帮助读者更好地理解不同避撞方式的应用场景和技术细节。 适合人群:汽车工程技术人员、交通安全研究人员、自动驾驶开发者。 使用场景及目标:适用于研究和开发车辆主动避撞系统的专业人士,旨在提高对避撞策略的理解,优化避撞算法的设计,提升行车安全性。 其他说明:文章不仅提供了理论分析,还结合了具体的数学模型和程序实现,使读者能够从多个角度全面掌握车辆避撞技术的关键要素。
基于MPPSK调制的数字对讲机系统.pdf