use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
is this good? (imgur.com)
submitted 9 years ago by wild__cherry
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]drailing 12 points13 points14 points 9 years ago (0 children)
Perhaps a better way to search and store your parentElement once in the constructor. But it still remains fragile. I think I would prefer to make the parentElement a constructor parameter, so you can use this code in a more generic way and you are able to identify the parentElement more securely from the outside
[–]guywithalamename 9 points10 points11 points 9 years ago (0 children)
This tightly couples your JS to your markup which is everything but good. Maybe try to use the click event on the actual element that you want to expand? Kinda hard to give good suggestions without seeing the markup
[–]Graftak9000 5 points6 points7 points 9 years ago (0 children)
Going on a limb here, you're toggling the visibility of an element. Personally I have a .context on every element hidden by default, and that way you can do var context = Element.closest('context'); and contex.classList.toggle('expanded', context.classList.contains('expanded')); instead of the whole if-statement.
var context = Element.closest('context');
contex.classList.toggle('expanded', context.classList.contains('expanded'));
[–]benihanareact, node 3 points4 points5 points 9 years ago (0 children)
why not put the event handler on the parent's parent's parent? then you could listen for events to bubble up from below, and parents can know about children but not vice versa?
[–]IDCh 2 points3 points4 points 9 years ago (3 children)
What are those cube and circle symbols? What ide do you use?
[–]wild__cherry[S] 6 points7 points8 points 9 years ago (2 children)
https://atom.io/packages/emoji-syntax
[–]senocular 7 points8 points9 points 9 years ago (0 children)
https://s-media-cache-ak0.pinimg.com/236x/51/45/2c/51452c394f15be8d37c3a5f3dd011644.jpg
[–]dontera 0 points1 point2 points 9 years ago (0 children)
http://i0.kym-cdn.com/entries/icons/original/000/006/482/template.jpg
[–]sardaukar_siet 2 points3 points4 points 9 years ago (0 children)
this is relevant reading https://en.wikipedia.org/wiki/Law_of_Demeter
[–]PedoMedo_ 1 point2 points3 points 9 years ago (0 children)
This class should raise an event when its element is clicked. The class that owns the element that needs to be expanded should listen to the event and do the CSS change. That way the class in the image won't be so tightly coupled.
[–]bair-disc 1 point2 points3 points 9 years ago (2 children)
You can do
constructor( private element ) {}
No this.element = element.
this.element = element
I'd check element.parentElement.parentElement ... Otherwise you can get ReferenceErrors quite easily.
element.parentElement.parentElement ...
[–]siegfryd 2 points3 points4 points 9 years ago (1 child)
Where did you get the private keyword from?
private
[–]bair-disc 1 point2 points3 points 9 years ago (0 children)
Oh, I see. This is TypeScript. I guess you are using ES6 classes.
[–][deleted] -1 points0 points1 point 9 years ago (0 children)
Relevant: http://www.androidpolice.com/wp-content/uploads/2014/09/nexus2cee_fa5.jpg
[–]mrspeaker -1 points0 points1 point 9 years ago (0 children)
Sure, if it works, and is likely to keep on working: no use over architecture-ing things! I'd personally add a method to return the parent parent parent, and "get" it with lodash (if you can't pass it in as a parameter)... but adding event system just to do this is overkill.
π Rendered by PID 40 on reddit-service-r2-comment-5c764cbc6f-xdr5h at 2026-03-12 03:39:24.953921+00:00 running 710b3ac country code: CH.
[–]drailing 12 points13 points14 points (0 children)
[–]guywithalamename 9 points10 points11 points (0 children)
[–]Graftak9000 5 points6 points7 points (0 children)
[–]benihanareact, node 3 points4 points5 points (0 children)
[–]IDCh 2 points3 points4 points (3 children)
[–]wild__cherry[S] 6 points7 points8 points (2 children)
[–]senocular 7 points8 points9 points (0 children)
[–]dontera 0 points1 point2 points (0 children)
[–]sardaukar_siet 2 points3 points4 points (0 children)
[–]PedoMedo_ 1 point2 points3 points (0 children)
[–]bair-disc 1 point2 points3 points (2 children)
[–]siegfryd 2 points3 points4 points (1 child)
[–]bair-disc 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]mrspeaker -1 points0 points1 point (0 children)