jquery.entwine icon indicating copy to clipboard operation
jquery.entwine copied to clipboard

What is ._super()?

Open patricknelson opened this issue 9 years ago • 2 comments
trafficstars

Shouldn't there be documentation covering the purpose and usefulness of this mysterious this._super() method? I see it and I think I know what it does, but I'm not sure. I'm not sure what the standards are for how/when it should be used (if it should be treated like PHP's parent::method() or ES6's super.method())?

I'm confused, since I want to do things The Right Way (tm) but I don't know exactly what this does per se.

patricknelson avatar Jun 12 '16 22:06 patricknelson

Check the tutorial here.

microcipcip avatar Nov 08 '16 15:11 microcipcip

A little bit of a rant here, but this seems a bit magical:

... it means that any other code that has added handlers for the current event (e.g. ‘onmatch’) to any of the DOM elements that match your selector will also run - it’s a vaguely similar pattern to parent::__construct() in PHP.

How can this compare to PHP? I ask since at least in PHP, there's an explicit declaration happening at the syntactical level defining a very clear inheritance hierarchy (i.e. if you call parent::methodName() you will be certain about which class this is being called on. Based on what I'm seeing This more mimics event listeners or maybe an observer pattern. In this case, there's no point in calling _super() because this functionality doesn't necessarily allow you to define any sort of actual order, just depends on which happens to run first; i.e. unpredictability (which ever happens to get to the finish line). So:

...if you’re adding extra functionality call this._super() after your code, if you’re replacing functionality then don’t

That doesn't make sense to me. What assurance is there that two aren't two implementations of onmatch were defined, both missing the this._super() call with the assumption that they are overriding the other (but only one "winning")? To me this would cause some issues that would be pretty difficult to debug, since you could write some code which happens to match the same as another selector, not realizing that even though you are calling this._super(), the other code may not be, and would wonder why it never runs (causing more difficulty with determining how to unobtrusively get your code to run without being un-maintainable or modifying core code somewhere).

Not only that, but we'll want to hash out exactly which things get executed when you call this._super(). That is, does it only allow overrides to methods (if omitted, or execute if not omitted) other instances of an exact match on the full jQuery selector (with/without entwine namespace?), or, on any elements?

/rant

TL;DR: Makes me wonder why this method exists. Would make more sense to get rid of it unless we can find a good way to explicitly and expressively debug and define an order of execution to ensure it's easy to patch into without modifying someone else's core/included code.

patricknelson avatar Nov 08 '16 20:11 patricknelson