Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"self" is a reserved keyword #8

Closed
taitems opened this issue May 6, 2011 · 7 comments
Closed

"self" is a reserved keyword #8

taitems opened this issue May 6, 2011 · 7 comments
Assignees

Comments

@taitems
Copy link
Owner

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
@jgv
Copy link

jgv commented May 6, 2011

self is not a reserved keyword. see https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words

@taitems
Copy link
Owner Author

taitems commented May 11, 2011

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

http://code.jquery.com/jquery-1.6.js

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

Closing :)

@taitems taitems closed this as completed May 11, 2011
@ehynds
Copy link

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
Copy link
Owner Author

taitems commented May 11, 2011

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

@jgv
Copy link

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.

@tbranyen
Copy link

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
Copy link
Owner Author

taitems commented Jun 11, 2011

Fixed locally, pending commit.

@taitems taitems closed this as completed Jun 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants