super keyword unexpected here

前端 未结 1 1807
故里飘歌
故里飘歌 2020-12-01 23:49

According to ES6 shorthand initialiser, following 2 methods are same:

In ES5

var person = {
  name: \"Person\",
  greet: function() {
     return \         


        
相关标签:
1条回答
  • So, why do we get error?

    Because super is only valid inside methods. greet: function() {} is a "normal" property/function, not a method, because it doesn't follow the method syntax.

    The differences between a method and a normal function definition are:

    • Methods have a "HomeObject" which is what allows them to use super.
    • Methods are not constructable, i.e. they cannot be called with new.
    • The name of a method doesn't become a binding in the method's scope (unlike named function expressions).
    0 讨论(0)
提交回复
热议问题