I see that most frameworks do not use the keyword super on their object, instead they use something like _super

I understand that it's a keyword but is it safe & acceptable to use it as a method name like this

var Class = function() {
   this.super = function(){};
};


var instance = new Class()
instance.super()

It works fine in Chrome with "use strict" mode on.

Side note, I know that coffeescript "escapes" it like this["super"], surely their must be a real reason for that.

有帮助吗?

解决方案

In ECMAScript 5, all keywords can be used as property identifiers. Old browsers will fail, so if you need to support old ones, you'd need to use the ["super"] syntax.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top