【发布时间】:2012-02-04 14:52:22
【问题描述】:
我与一些高级 JavaScript 人员一起工作,他们在代码中使用了 SUPER 关键字。我承认,我不太了解如何以及为什么可以并且会使用它。
有人可以指导我或告诉我如何精通它的用法和推理吗?
这里有一些例子:
openup: function( $super ) {
$super();
this.shop.enable_access();
}
addLeft: function( data ) {
var cell = Element('td');
if ( data.item_data ) {
var item = new SRIL(data.item_data);
item.attach(cell);
item.show();
}
return cell;
}
var SRIL = Class.create(Module, {
initialize: function( $super, data ) {
$super({ dom: 'show_line' });
this.data = data;
if ( data.Type[0] == 'Car' ) {
//some code
}
else {
// some code
}
}
});
【问题讨论】:
-
您是指
SUPER还是super?案件很重要。 -
$super改变了一些东西——它不是关键字,而只是一个变量。 -
在我看来,这段代码是基于 Prototype.js 框架构建的:prototypejs.org/learn/class-inheritance
标签: javascript keyword superclass super