怎么&为什么在代码中使用SUPER? [英] How & Why to use SUPER in code?

查看:182
本文介绍了怎么&为什么在代码中使用SUPER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与一些高级JavaScript人员合作,他们在代码中使用了SUPER关键字。我承认,我不太清楚如何以及为什么能够并且会使用它。

I work with some advanced JavaScript people and they have used the SUPER keyword in their code. I admit, I don't have a good grasp of how and why one can and would use this.

有人可以指导我或告诉我如何精通它的用法和推理?

Can someone direct me or show me how to become well versed in its usage and reasoning thereof?

以下是一些例子:

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
    }
}

});

推荐答案

JavaScript没有这样的东西。

JavaScript does not have such a thing.

更新:你应该看看文档这里使用的图书馆。这是一个库功能,而不是语言功能。

Update: You should have a look at the documentation of the library that is in use here. This is a library feature, not a language one.

这篇关于怎么&为什么在代码中使用SUPER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆