prototype.js中的class.create()方法

prototype.js中的class.create()方法Class.createClass.create([superclass][,methods…])→Classsuperclass (Class) –Theoptionalsuperclasstoinheritmethodsfrom.methods (Object) –Anobjectwhosepropertiesw

大家好,又见面了,我是你们的朋友全栈君。

Class.create

Class.create([superclass][, methods...]) → Class
  • superclass (Class) – The optional superclass to inherit methods from.
  • methods (Object) – An object whose properties will be “mixed-in” to the new class. Any number of mixins can be added; later mixins take precedence.

Class.create creates a class and returns a constructor function for instances of the class. Calling the constructor function (typically as part of a new statement) will invoke the class’s initialize method.

Class.create accepts two kinds of arguments. If the first argument is a Class, it’s used as the new class’s superclass, and all its methods are inherited. Otherwise, any arguments passed are treated as objects, and their methods are copied over (“mixed in”) as instance methods of the new class. In cases of method name overlap, later arguments take precedence over earlier arguments.

If a subclass overrides an instance method declared in a superclass, the subclass’s method can still access the original method. To do so, declare the subclass’s method as normal, but insert $super as the first argument. This makes $super available as a method for use within the function.

To extend a class after it has been defined, use Class#addMethods.

For details, see the inheritance tutorial on the Prototype website.

链接:http://www.prototypejs.org/api

小demo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var 
Animal = Class.create();
Animal.prototype = {
  
initialize: 
function
(name, sound) {
    
this
.name  = name;
    
this
.sound = sound;
  
},
  
speak: 
function
() {
    
alert(name + 
" says: " 
+ sound + 
"!"
);
  
}
};
var 
snake = 
new 
Animal(
"Ringneck"

"hissssssssss"
);
snake.speak();
// -> alerts "Ringneck says: hissssssssss!"
var 
Dog = Class.create();
Dog.prototype = Object.extend(
new 
Animal(), {
  
initialize: 
function
(name) {
    
this
.name  = name;
    
this
.sound = 
"woof"
;
  
}  
});
 
 
var 
fido = 
new 
Dog(
"Fido"
);
fido.speak();
 
// -> alerts "Fido says: woof!"

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/163401.html原文链接:https://javaforall.net

(0)
上一篇 2022年7月22日 下午11:36
下一篇 2022年7月22日 下午11:36


相关推荐

  • 文件管理学习:从百度网盘搬家onedrive测评「建议收藏」

    文件管理学习:从百度网盘搬家onedrive测评「建议收藏」网上已经有很多多家网盘对比的文章了。由于我平时依赖微软系列比较多,常用office,有自己的微软邮箱,科学上网跟吃饭一样(这克服了网页版被qiang的障碍)。所以最后我选择了onedrive,基于上述前提,搬家就是个一蹴而就的事。微软普通账户只有5G免费,要扩容得花钱至少15/月,然后查到了免费扩容的办法,那就是用edu邮箱注册。学校的edu邮箱终于有了用武之处。。用教育邮箱注册office…

    2025年9月3日
    13
  • SPPnet

    SPPnet目录1.Motivation2.SPPnet2.1SPP层的原理2.2SPPnet的区域映射原理3.总结论文:SpatialPyramidPoolinginDeepConvolutionalNetworksforVisualRecognition.来源:ECCV20141.MotivationR-CNN模型存在很多缺点和可改进的地方,其中的两个缺点如下:CNN网络后面接的FC层需要固定的输入大小,导致CNN也需要固定大小的输入,即要求候选区域在进入CNN前需要c

    2022年4月27日
    57
  • JDK卸载删除

    JDK卸载删除Java卸载1.进入环境变量,点击Java_Home2.进入路径,删除JDK清理环境变量删除path下关于Java的环境变量查看是否清除cdm运行输入java-version

    2022年6月20日
    36
  • hdu 5685

    hdu 5685

    2021年5月26日
    109
  • Excel均方误差计算公式_随机误差项的方差估计量推导

    Excel均方误差计算公式_随机误差项的方差估计量推导在Excel表中,有时需要计算方差,然后根据此图绘制图表,目标值指示偏差程度,然后如何计算方差?方差的概念方差是每个数据与平均值之间差异的平方和的平均值.在概率论和数理统计中,方差(英语方差)用于衡量随机变量与其数学期望值(即均值)之间的偏差程度.均方误差的概念也称为标准偏差,它是每个数据与平均值的距离的平均值.它是平方的平方根和与平均值的偏差的平均值.标准偏差可以反映数据集的分散程度.如…

    2022年9月30日
    4
  • mysql分页查询倒序_【Mysql笔记】MySQL实现分页查询[通俗易懂]

    limit基本实现方式一般情况下,客户端通过传递pageNo(页码)、pageSize(每页条数)两个参数去分页查询数据库中的数据,在数据量较小(元组百/千级)时使用MySQL自带的limit来解决这个问题:收到客户端{pageNo:1,pagesize:10}select*fromtablelimit(pageNo-1)*pageSize,pageSize;收到客户端{pa…

    2022年4月15日
    201

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号