- 浏览: 445478 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (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 1349link archor http://www.x ... -
js closure
2012-03-02 18:21 1072js closure scope: in j ... -
js array methods
2012-03-02 15:14 2490js array method array ha ... -
js logic operator
2012-01-16 21:41 921logical expression of js ... -
js 检验 Array
2011-01-01 20:13 866检验是否是 Array 工具方法: function ... -
heap sort
2010-12-18 19:09 1217heapsort ------ heap 数据结构 hea ... -
js 图片延迟加载
2010-11-20 17:04 1612图片延迟加载 ------ 需求场景: 对于长页面,如果有 ... -
js 的 null & undefined 判断
2010-10-25 23:35 2216判断 null 或 undefined ------ 判断规 ... -
chrome 开发人员工具
2010-10-08 15:33 1684chrome 有自己的开发人员工具,类似 firefox 的 ... -
apply() & call()
2010-09-24 19:24 1079apply & call Function 对象 调 ... -
ascii & char & string of js
2010-09-11 19:02 3410ascii & char & string ... -
js String trim()
2010-09-10 00:06 17688为 js 添加 trim() 功能 js 默认不支持 tri ... -
js 实现 本地图片 预览
2010-08-26 10:59 3432js 实现 本地图片 预览 <!DOCTYPE H ... -
bassistance 's jquery plugin
2010-04-27 13:20 1263该网址下有些比较好用的 jquery plugin http ... -
andrew-hoyer webside
2010-03-05 17:18 880andrew-hoyer 's webside is fun, ... -
raphael js lib
2010-03-05 11:03 2635raphael js 是超级炫的 js 库,提供对 web 矢 ... -
js 倒计时
2010-03-03 18:00 3888写了个超简单的 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. **类实例方法**:这些方法属于类的实例,每个实例都可以有自己的...
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
前端分析-2023071100789
基于kinect的3D人体建模C++完整代码.cpp
搞机工具箱10.1.0.7z
GRU+informer时间序列预测(Python完整源码和数据),python代码,pytorch架构,适合各种时间序列直接预测。 适合小白,注释清楚,都能看懂。功能如下: 代码基于数据集划分为训练集测试集。 1.多变量输入,单变量输出/可改多输出 2.多时间步预测,单时间步预测 3.评价指标:R方 RMSE MAE MAPE,对比图 4.数据从excel/csv文件中读取,直接替换即可。 5.结果保存到文本中,可以后续处理。 代码带数据,注释清晰,直接一键运行即可,适合新手小白。
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
基于ANSYS LSDyna的DEM-SPH-FEM耦合模拟滑坡入水动态行为研究,基于ANSYS LSDyna的DEM-SPH-FEM耦合的滑坡入水模拟分析研究,基于ansys lsdyna的滑坡入水模拟dem-sph-fem耦合 ,基于ANSYS LSDyna; 滑坡入水模拟; DEM-SPH-FEM 耦合,基于DEM-SPH-FEM耦合的ANSYS LSDyna滑坡入水模拟
auto_gptq-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
复件 复件 建设工程可行性研究合同[示范文本].doc
13考试真题最近的t64.txt
好用我已经解决报错问题
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!
auto_gptq-0.4.2-cp38-cp38-win_amd64.whl
自动立体库设计方案.pptx
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!