javascript - this._super() vs this.super() - Stack Overflow

I'm wondering why a framework like EmberJS uses the _super method for calling the overriddenmeth

I'm wondering why a framework like EmberJS uses the _super method for calling the overridden method on the extended object instead of the (in my opinion) more logical this.super.

Is there a specific reason for this, for instance that super is a reserved keyword in javascript? So you cannot assign variables or named functions to the name super. The function assigned to this.super is an anonymous function right?

I'm wondering why a framework like EmberJS uses the _super method for calling the overridden method on the extended object instead of the (in my opinion) more logical this.super.

Is there a specific reason for this, for instance that super is a reserved keyword in javascript? So you cannot assign variables or named functions to the name super. The function assigned to this.super is an anonymous function right?

Share asked Aug 29, 2014 at 12:58 Willem de WitWillem de Wit 8,7529 gold badges58 silver badges90 bronze badges 2
  • 1 It's just coding style. – Barmar Commented Aug 29, 2014 at 13:01
  • 2 super has been a Future Reserved Word in all previous editions of ECMAScript. The 5th edition did permit the user of reserved words as (unquoted) properties. But, IE8 for example might throw a syntax error as it was based on the 3rd edition. – Jonathan Lonowski Commented Aug 29, 2014 at 13:13
Add a ment  | 

2 Answers 2

Reset to default 3

_ indicates a private member. You're only supposed to access _super from inside the class, never from the outside.

_super may be used to differenate it between other functions that may have been set. This could have been to show how it's special, or different than other variables. Or it could be to show it's private.

See:

When do you make an underscore in front of an instance variable?

How does an underscore in front of a variable in a cocoa objective-c class work?

Why do we use _ in variable names?

EDIT: Like Barmar said (except in much less words) it's a coding style, nothing else.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744915433a4600803.html

相关推荐

  • javascript - this._super() vs this.super() - Stack Overflow

    I'm wondering why a framework like EmberJS uses the _super method for calling the overriddenmeth

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信