2

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?

Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
  • 1
    It's just coding style. – Barmar Aug 29 '14 at 13:01
  • 2
    `super` has been a [*Future Reserved Word*](http://ecma-international.org/ecma-262/5.1/#sec-7.6.1.2) 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 Aug 29 '14 at 13:13

2 Answers2

3

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

panta82
  • 2,763
  • 3
  • 20
  • 38
1

_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.

Community
  • 1
  • 1
warspyking
  • 3,045
  • 4
  • 20
  • 37