"self" is a reserved keyword #8

taitems opened this Issue May 6, 2011 · 7 comments


None yet
4 participants

taitems commented May 6, 2011

Self is a reserved keyword, use _self instead.

As per: http://news.ycombinator.com/item?id=2519614

@ghost ghost assigned taitems May 6, 2011


taitems commented May 11, 2011

Yep, I didn't think so. I remembered seeing it used throughout the jQuery code too.


Do a ctrl + f > "var self =" ...

Closing :)

@taitems taitems closed this May 11, 2011

ehynds commented May 11, 2011

+1 on at least renaming it.

self isn't a reserved word but it is a native property of the window object in firefox/webkit. If you're referring to self and had forgotten to var scope it, it'll actually refer to the window object, which can make debugging difficult. It's for this reason that jQuery UI is pushing to rename instances of var self = this; (see http://bugs.jqueryui.com/ticket/5404/ )

@taitems taitems reopened this May 11, 2011


taitems commented May 11, 2011

Thank you for this, re-opening the issue for consideration.

jgv commented May 11, 2011

while self is not a reserved keyword, @ehynds makes a good point. You could possibly go for something like _self unless that conflicts with Underscore.js naming conventions.

These front-end guidelines should not be promoting leaking globals at all. It would be the same as saying you cannot use the word frames in your code since it conflicts with a property on the window object. _self looks ugly and is unnecessary.

Perhaps just discuss the fact that self is a property on the window object and if you leak it globally it will override... and that you shouldn't be leaking a word to describe something internal anyways.

My 2 cents.


taitems commented Jun 11, 2011

Fixed locally, pending commit.

@taitems taitems closed this Jun 11, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment