Closed hmdne closed 3 years ago
I guess, it can be done in custom way, like:
$win = $windows
$doc = $document
That's all. Ruby is against short names, JavaScript does not have those aliases. So I don't like this idea for general Opal.
The extended names have the undeniable advantage of being recognizable by anyone who has done any JS in their life. But I've shortened them in apps multiple times, especially for quick scripts.
So I see both sides, but I'm probably more inclined of leaving the shortened version to application code, or to support both.
Is win
the "victory"? Is doc
the "doctor"? :grimacing:
I understand the desire to write less letters, but… I'm against this approach in common (Ruby) libraries. You can do this at team-level (or project-level).
For example, we have:
Excessively short identifiers: the name of a variable should reflect its function unless the function is obvious.
$win
is not $w
and $doc
is not $d
. In a context of browser-executable code, in my opinion, $win
and $doc
are no less obvious than full names and a syntax like $doc[".list-item"]
would be easily recognizable as an equivalent of jQuery $(".list-item")
(and much more visually similar than $document[".list-item"]
) - and that's my primary reason behind this proposal - I actually try to ease migration for those users with many of my recent commits to this project. I agree this particular proposal is a bit controversial.
@ahmadine I'm ok with it if it's opt-in, e.g. by requiring a file (e.g. require 'browser/shorthands'
or something, this is the first name that came to mind!).
I find it a bit frustrating to type the names of the global variables (
$window
,$document
) so much. I would suggest adding some non-invasive shortcuts for those:$win
,$doc
.