prototype.js中的class.create()方法
来源:互联网 发布:淘宝司法拍卖车靠谱吗 编辑:程序博客网 时间:2024/06/06 21:39
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:
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!"
- prototype.js中的class.create()方法
- create 方法(prototype)
- prototype、js中的三种方法、call
- js技巧--创建class时调用prototype原型方法
- Prototype的Class.create函数解析
- 一个帮助你理解prototype中Class.create()方法的例子
- js中的prototype chain
- JS中的prototype
- js库prototype中的$()
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- JS中的prototype
- iOS11带来的技术变化注意事项
- CentOS7.64位下安装jdk8
- rk3288对于parameter参数文件的解析处理
- ftp被动与主动模式的区别
- python_lintcode_166链表倒数第n个节点_671循环单词
- prototype.js中的class.create()方法
- PHP合并和追加数组
- 文科生的反击——新书《你能做任何工作:“无用”的自由技艺的惊人力量》解读
- 《统计自然语言处理》笔记(2)
- 递归-OpenJudge-8758:2de
- 深入理解GC ——MinorGC\MajorGC\FullGC
- extjs tree 展开指定层级
- 学习日志(java类与方法)
- 动态代理与AOP(1)